Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active February 2, 2024 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspose-com-gists/a84c46e782e6befe28d8ab7ee34fbf38 to your computer and use it in GitHub Desktop.
Save aspose-com-gists/a84c46e782e6befe28d8ab7ee34fbf38 to your computer and use it in GitHub Desktop.
Add Comments in Excel Worksheet using Python
# Instantiating a Workbook object
workbook = Workbook("workbook.xlsx")
# Obtaining the reference of the first worksheet by passing its sheet index
worksheet = workbook.getWorksheets().get(0)
# Adding a comment to "F5" cell
commentIndex = worksheet.getComments().add("F5")
# Accessing the newly added comment
comment = worksheet.getComments().get(commentIndex)
# Setting the comment note
comment.setNote("Hello Aspose!")
# Saving the Excel file
workbook.save("output.xlsx")
# Instantiating a Workbook object
workbook = Workbook("workbook.xlsx")
# Obtaining the reference of the first worksheet by passing its sheet index
worksheet = workbook.getWorksheets().get(0)
# Adding a comment to "F5" cell
commentIndex = worksheet.getComments().add("F5")
# Accessing the newly added comment
comment = worksheet.getComments().get(commentIndex)
# Setting the comment note
comment.setNote("Hello Aspose!")
# Setting the font size of a comment to 14
comment.getFont().setSize(14)
# Setting the font of a comment to bold
comment.getFont().setBold(True)
# Setting the height of the font to 10
comment.setHeightCM(10)
# Setting the width of the font to 2
comment.setWidthCM(2)
# Saving the Excel file
workbook.save("output.xlsx")
@rohitvishwakarma-sf
Copy link

this is a note not commnet.
How to add comment ? the new excel threaded comments ?

@aspose-com-gists
Copy link
Author

aspose-com-gists commented Feb 2, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment