I'm a python programmer and I have to insert notes in mass in an excel spreadsheet. Does anybody knows some way that's easy/practical using a python script? (could be a java script, if it had examples).
It can be on a .xls, .xlsx or .ods, and can be in any OS (although I'm a linux user, so if I could have my solution portable to linux, it would be better).
I've tried xlwt module for python and searched for someway to do this using csv, but no success.
解决方案
Here's some python code that uses the pywin32 package on Windows to start Excel, open a 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'')
>>> sheet = wb.ActiveSheet
>>> sheet.Range("A1").AddComment()
>>> sheet.Range("A1").Comment.Visible = True
>>> sheet.Range("A1").Comment.Text("Hello World")
u'Hello World'
>>> wb.SaveAs(r'')
>>> wb.Close()
>>> xl.Quit()
I just ran this code using python 2.7.2 on Windows 7 with Excel 2007 and it worked for me.