Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Feat: Add low level comments and comment replies support#1467

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
bhavasagar-dv wants to merge14 commits intopython-openxml:master
base:master
Choose a base branch
Loading
fromDiligenceVault:feat/low-level-comments-support

Conversation

bhavasagar-dv
Copy link

@bhavasagar-dvbhavasagar-dv commentedJan 31, 2025
edited
Loading

Feature: Enhanced Word Document Comments and comment replies Support

This pull request adds comprehensive support for comments and comment replies in Word documents, introducing new capabilities for handling comment metadata and references.

New Capabilities:

  1. Add comments to paragraphs.
  2. Creating threads with the existing comments.
  3. Spaning comments across multiple paragraphs.

Example Usage:

from docx import Documentdocument = Document("sample.docx")p = document.add_paragraph("This is an example paragraph")parent_comment = p.add_comment(    "Testing Comment",    author="Test Author",    initials="TA",    date="2025-01-01 00:00:00",    resolved=True,)p.add_comment(    "Testing Comment Reply 1",    author="Test Author",    initials="TA",    date="2025-01-01 00:00:00",    resolved=True,    parent=parent_comment,)p.add_comment(    "Testing Comment Reply 2",    author="Test Author",    initials="TA",    date="2025-01-01 00:00:00",    resolved=True,    parent=parent_comment,)document.save("add_comments.docx")

To mark a comment over multiple paragraphs or just a single run

from docx import Documentdocument = Document("sample.docx")para = document.add_paragraph()comment = para.mark_comment_start("testing comment", "Test Author", "TA", "2025-01-01 00:00:00")comment2 = para.mark_comment_start(    "testing comment reply", "Test Author", "TA", "2025-01-01 00:00:00", parent=comment)para.add_run("Some random text")para2 = document.add_paragraph("Another para")para2.mark_comment_end(comment.id)para2.mark_comment_end(comment2.id)para2.add_run("Lorem ipsum dolor sit amet")document.save("add_comments.docx")

Fixes the issue:#93

Another similar PR#624 but it doesn't address the comment replies. So, I have created this PR.

myedibleenso reacted with hooray emoji
@bhavasagar-dv
Copy link
Author

@scanny can you please look into this, and if any changes are required please let us know, we are happy to contribute to this feature. Thanks.

…aphs.Add `mark_comment_start` and `mark_comment_end` methods to support comments spanning across multiple paragraphs
@rdaim
Copy link

thanks,can you add a comment to a run? like this:

run = paragraph2.add_run('text1') #add a run to the paragraph

run.add_comment('comment') # add a comment only for the run text

run.add_comment('comment2')

run_comments = run.comments

@bhavasagar-dv
Copy link
Author

@rdaim we can add a comment for arun like this.

from docx import Documentdocument = Document("sample.docx")para = document.add_paragraph()comment = para.mark_comment_start("testing comment", "Test Author", "TA", "2025-01-01 00:00:00")para.add_run("Some random text with a comment. ")para.mark_comment_end(comment.id)para.add_run("This text doesn't have a comment")document.save("add_comments.docx")
rdaim reacted with thumbs up emoji

@rdaim
Copy link

@rdaim we can add a comment for arun like this.

from docx import Documentdocument = Document("sample.docx")para = document.add_paragraph()comment = para.mark_comment_start("testing comment", "Test Author", "TA", "2025-01-01 00:00:00")para.add_run("Some random text with a comment. ")para.mark_comment_end(comment.id)para.add_run("This text doesn't have a comment")document.save("add_comments.docx")

wowww, thanks a lot!

@neilrathi01
Copy link

hi@bhavasagar-dv, What if a comment already exists and is linked to a certain paragraph, is there a way to reply to that comment using this?

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

3 participants
@bhavasagar-dv@rdaim@neilrathi01

[8]ページ先頭

©2009-2025 Movatter.jp