Add comment to excel using python win32

2019-03-04 08:59发布

问题:

I am trying to add new comment to excel with python, using win32.

import win32com.client as win32
excel = win32.gencache.EnsureDispatch('Excel.Application')
wb = excel.Workbooks.Open(r'C:\...\.xlsx')
ws = wb.Worksheets('sheet1')
ws.Cells(1,1).AddComment = "comment"

--> object has no attribute 'AddComment'

Do you know how to add new comment to excel using win32? Thank you!

回答1:

Add comment is a method not a property.

ws = wb.Worksheets('sheet1')
ws.Cells(1,1).AddComment("comment")

Just read the the documentation in the MSDN.