下面是一个使用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