使用python win32向excel添加注释

Ale*_*eks 1 python excel comments xlsx win32com

我正在尝试使用 win32 使用 python 添加新注释到 excel。

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"
Run Code Online (Sandbox Code Playgroud)

--> 对象没有属性“AddComment”

你知道如何使用win32向excel添加新注释吗?谢谢你!

xMR*_*MRi 5

添加注释是一种方法而不是属性。

ws = wb.Worksheets('sheet1')
ws.Cells(1,1).AddComment("comment")
Run Code Online (Sandbox Code Playgroud)

只需阅读MSDN 中的文档即可。