1

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!

2
  • What's the reason, that you are using win32 over openpyxl or xlsxwriter ? Commented Nov 10, 2017 at 12:09
  • Because I should save exciting xlsx file format (charts, images..) Commented Nov 10, 2017 at 12:21

1 Answer 1

5

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.

Sign up to request clarification or add additional context in comments.

5 Comments

Thank you very much for answer and documentation!
As you are new to stackoverflow. Mark it also as an answer if it solves the problem!
Do you know how delete exciting comment? I tryed ws.Cells(1,1).ClearComments, but it don't work.
ws.Cells(1,1).Comment.Delete() - works! msdn.microsoft.com/en-us/vba/excel-vba/articles/…
Use a new question for such cases. Stackoverflow is not a discussion platform.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.