下面是一個使用pywin32包在Windows上一些Python代碼來啓動Excel,打開電子表格並創建單元格A1評論:
>>> import win32com.client
>>> xl = win32com.client.Dispatch("Excel.Application")
>>> xl.Visible = 1
>>> wb = xl.Workbooks.Open(r'<full path of excel spreadsheet>')
>>> sheet = wb.ActiveSheet
>>> sheet.Range("A1").AddComment()
<COMObject AddComment>
>>> sheet.Range("A1").Comment.Visible = True
>>> sheet.Range("A1").Comment.Text("Hello World")
u'Hello World'
>>> wb.SaveAs(r'<full path of modified spreadsheet>')
>>> wb.Close()
>>> xl.Quit()
我只是跑使用Python 2.7.2這段代碼在Windows 7與Excel 2007和它爲我工作。
謝謝!將在這裏測試。 – user888360 2012-03-15 23:43:13