from docx import Document
# Open the document
document = Document('example.docx')
# Find the text you want to add a comment to
for paragraph in document.paragraphs:
if 'text to comment on' in paragraph.text:
# Get the run of text that contains the text to comment on
for run in paragraph.runs:
if 'text to comment on' in run.text:
# Add the comment
comment = paragraph.add_comment('Comment text', author='Author Name')
run.text = run.text.replace('text to comment on', '')
# Save the document
document.save('example.docx')
1条答案
按热度按时间kknvjkwl1#
假设你正试图评论一个“特定”的文本,这种方法可以帮助: