Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save aspose-com-kb/12c2d18258d29012b1200556314571fe to your computer and use it in GitHub Desktop.
Save aspose-com-kb/12c2d18258d29012b1200556314571fe to your computer and use it in GitHub Desktop.
Code to Insert Comment in Word using Python. For more details: https://kb.aspose.com/words/python/how-to-insert-comment-in-word-using-python/
import aspose.words as aw
from datetime import date
# Load the license
wordToHtml = aw.License()
wordToHtml.set_license("Aspose.Total.lic")
# Create a document
doc = aw.Document()
# Create a document builder and write some text to the file
builder = aw.DocumentBuilder(doc)
builder.write("Hello world!")
# Create a comment
comment = aw.Comment(doc, "John Doe", "JD", date.today())
# Add a comment to the builder class object
builder.current_paragraph.append_child(comment)
# Create a paragraph for adding text to the comment
builder.move_to(comment.append_child(aw.Paragraph(doc)))
# Write comment text
builder.write("Comment text.")
# Save the document with comments
doc.save("FileWithComments.docx")
print ("Comments added successfully in the Word file")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment