Learn how to Read, Add, and Edit Threaded Comments in Excel using Python
Created
February 1, 2024 15:44
-
-
Save aspose-com-gists/1ca33b35d960d5e37753cdf314425c13 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This code example demonstrates how to add threaded comments in an Excel worksheet | |
# Create an instance of the Workbook class | |
workbook = Workbook(); | |
# Add an Author | |
authorIndex = workbook.worksheets.threaded_comment_authors.add("Aspose Test", "", ""); | |
author = workbook.worksheets.threaded_comment_authors[authorIndex]; | |
# Add Threaded Comment | |
workbook.worksheets[0].comments.add_threaded_comment("A1", "Test Threaded Comment", author); | |
# Save the output file | |
workbook.save("D:\\Files\\AddThreadedComments_out.xlsx"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This code example demonstrates how to delete threaded comments in an Excel worksheet | |
# Load an existing Excel file | |
workbook = Workbook("D:\\Files\\AddThreadedComments_out.xlsx") | |
# Get all the comments | |
comments = workbook.worksheets[0].comments | |
# Remove Comments | |
comments.remove_at("A1") | |
# Save the output file | |
workbook.save("D:\\Files\\DeleteThreadedComments.xlsx"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This code example demonstrates how to edit threaded comments in an Excel worksheet | |
# Load an existing Excel file | |
workbook = Workbook("D:\\Files\\AddThreadedComments_out.xlsx") | |
# Access the first worksheet | |
worksheet = workbook.worksheets[0]; | |
# Get Threaded Comments for a specific cell | |
threadedComments = worksheet.comments.get_threaded_comments("A1"); | |
comment = threadedComments[0] | |
# Update the comment note | |
comment.notes = "Updated Comment"; | |
# Save the output file | |
workbook.save("D:\\Files\\EditThreadedComments.xlsx"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This code example demonstrates how to read threaded comments for a specified cell in an Excel worksheet | |
# Load an existing Excel file | |
workbook = Workbook("D:\\Files\\AddThreadedComments_out.xlsx") | |
# Access the first worksheet | |
worksheet = workbook.worksheets[0]; | |
# Get Threaded Comments for a specific cell | |
threadedComments = worksheet.comments.get_threaded_comments("A1"); | |
# Read the threaded comments | |
for comment in threadedComments: | |
print("Author Name: " + comment.author.name) | |
print("Threaded comment Notes:" + comment.notes) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This code example demonstrates how to read all threaded comments from an Excel worksheet | |
# Load an existing Excel file | |
workbook = Workbook("D:\\Files\\MultipleThreadedComments_out.xlsx") | |
# Access the first worksheet | |
worksheet = workbook.worksheets[0]; | |
# Get all the comments | |
comments = worksheet.comments | |
# Read all the threaded comments | |
for comment in comments: | |
# Process threaded comments | |
for threadedComment in comment.threaded_comments: | |
print("Author Name: " + threadedComment.author.name) | |
print("Threaded comment author User Id: " + threadedComment.author.user_id) | |
print("Threaded comment author ProviderId:" + threadedComment.author.provider_id) | |
print("Threaded comment Notes:" + threadedComment.notes) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment