使用 python win32 向 excel 添加评论

Add comment to excel using python win32

我正在尝试使用 win32 向 excel 添加新评论 python。

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"

-->对象没有属性'AddComment'

您知道如何使用 win32 向 excel 添加新评论吗? 谢谢!

添加评论是一种方法,而不是 属性。

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

刚看完documentation in the MSDN.