美文网首页
win32com操作excel

win32com操作excel

作者: Aedda | 来源:发表于2021-05-10 17:52 被阅读0次
    import os
    from win32com.client import Dispatch, constants
    
    
    def fun():
        OBJ_PATH = os.path.dirname(os.path.realpath(__file__))
        app = Dispatch('Excel.Application')
        app.Visible = 1  # 0无窗口,1有窗口
        app.DisplayAlerts = 0 # 0无警告提示,1有警告提示
        WorkBook = app.Workbooks.Open(os.path.join(OBJ_PATH, "新建XLSX 工作表.xlsx"))
        sheet = WorkBook.Worksheets('sheet1')
        cell01_value = sheet.Cells(1, 1).Value
        print("cell01的内容为:", cell01_value)
        sheet.Cells(1, 2).Value = "win32com"
        WorkBook.SaveAs(os.path.join(OBJ_PATH, "修改操作练习1.xlsx"))
        WorkBook.Close()
        app.Quit()
    
    
    fun()
    
    

    相关文章

      网友评论

          本文标题:win32com操作excel

          本文链接:https://www.haomeiwen.com/subject/odwidltx.html