Here is the python code that the pywin32 package on Windows uses to run Excel, open the spreadsheet and create a comment in cell 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()
I just run this code using python 2.7.2 on Windows 7 with Excel 2007 and it worked for me.
source share