Add comment to excel using python win32

2019-03-04 09:06发布

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条回答
Evening l夕情丶
2楼-- · 2019-03-04 09:15

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.

查看更多
登录 后发表回答