Search code examples
pythonexcelcommentsxlsxwin32com

Add comment to excel using python win32


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!


Solution

  • 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.