Skip to content

low-level support for comments & footnotes - #624

Closed
BayooG wants to merge 118 commits into
python-openxml:masterfrom
BayooG:master
Closed

BayooG wants to merge 118 commits into
python-openxml:masterfrom
BayooG:master

Conversation

@BayooG

@BayooG BayooG commented Mar 1, 2019

Copy link
Copy Markdown

created two new parts for 'comments part' & 'footnotes part'
and now these parts can be accessed from the 'document part'
added new methods to the paragraph element so comments and footnote can be added easily

@leyiwang

leyiwang commented Mar 8, 2019

Copy link
Copy Markdown

@BayooG It's cool to improve docx package to support comments. I wonder if this part of the work has been implemented and I can't wait to know how to add a comment in a docx using this package, can you give an example?

@BayooG

BayooG commented Mar 8, 2019

Copy link
Copy Markdown
Author

@BayooG It's cool to improve docx package to support comments. I wonder if this part of the work has been implemented and I can't wait to know how to add a comment in a docx using this package, can you give an example?

Now you can add a comment for a certain paragraph
I added a method to docx.text.paragraph add_comment
Ex:
d = docx.Document()
p = d.add_paragraph(‘paragraph ‘)
c = p.add_comment(‘comment’)

Check my branch for more details
http://github.com/BayooG/bayoo-docx/tree/release/0.1.3

@BayooG

BayooG commented Jan 13, 2021

Copy link
Copy Markdown
Author

@scanny
is there any template for contribution, or what should I do to contribute?

@Barsovski

Barsovski commented Mar 18, 2021 •

Copy link
Copy Markdown

@BayooG good work on footnotes! But how can i change a footnote style like line_spacing and oth?
Tried this code:

f = row.cells[0].paragraphs[0].add_footnote('text')
f_format = f.paragraph.paragraph_format
f_format.space_before = Cm(0)
f_format.space_after = Cm(0)
f_format.line_spacing = Cm(0)

But in the final document there is a big indentation between footnote lines( like second empty line, and they occupy a lot of space on page.

@verydemo

verydemo commented Jul 14, 2021 •

Copy link
Copy Markdown

hello, Can I add comments in a word?
document.paragraphs[27].get_range(8,12).add_comment("hello comment")
The paragraph is offset (8, 12), I think in paragraphs, run should have a get_range method.

125562045-a45b5cd8-b3f6-47fa-9101-451a1bc60f77

python-docx add comment smallest object is run, MS add comment smallest object is any content .

@cnhuijiang

Copy link
Copy Markdown

May i ask if we can add footnotes on the run level now?

@floyddcn

Copy link
Copy Markdown

@BayooG It's cool to improve docx package to support comments. I wonder if this part of the work has been implemented and I can't wait to know how to add a comment in a docx using this package, can you give an example?

Now you can add a comment for a certain paragraph I added a method to docx.text.paragraph add_comment Ex: d = docx.Document() p = d.add_paragraph(‘paragraph ‘) c = p.add_comment(‘comment’)

Check my branch for more details http://github.com/BayooG/bayoo-docx/tree/release/0.1.3

work consider giving it a star
@BayooG
Splendid work!!! I checked the bayoo-docx and find it can write and retrieve comment well.
But i don't know how to write and retrieve comments across paragraphs or in cells(which i think is the same as 'across paragraphs' because under cells are lots of paragraphs).
If the 'comments across paragraphs' is not available yet ,is there any plan to support it in the future?

@sherrysdavis

Copy link
Copy Markdown

EndNote Full Torrent does as many tasks as possible automatically. As an example, it is able to automatically format and update bibliographies, for example
EndNote

ahmadalwareh and others added 7 commits October 31, 2022 21:10
* Update version

* reverse version to origin

* Add add_ole_object_to_run func
* Update version

* reverse version to origin

* Add add_ole_object_to_run func

* Update README

* Update README

* Update README

* Update README
* Update version

* reverse version to origin

* Add add_ole_object_to_run func

* Update README

* Update README

* Update README

* Update README

* Add fldChar element support

* Add instrText  element support

* Set instr_text element as a property

* Set instr_text element delete

* Avoid duplication if add instrtext element with run already has
Comment thread DESCRIPTION.rst

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not implement a delete_comment() function as well?

@Cayllen

Cayllen commented Mar 27, 2024 •

Copy link
Copy Markdown

Awesome work @BayooG ! Shame it's not merged yet. How would it be possible to span a comment across multiple paragraphs with this implementation?

@bhavasagar-dv

Copy link
Copy Markdown

@scanny can we know if this PR will be merged ?

@rodolvbg

rodolvbg commented Jun 4, 2024 •

Copy link
Copy Markdown

Hi, @BayooG, could you leave a simple solution to add a footnote, as long as this PR does not merge? BTW, nice job

@BayooG

BayooG commented Jun 6, 2024

Copy link
Copy Markdown
Author

Hi, @BayooG, could you leave a simple solution to add a footnote, as long as this PR does not merge? BTW, nice job

I have a fork, check this http://github.com/BayooG/bayoo-docx

@wschlecht

Copy link
Copy Markdown

I really appreciate this fork @BayooG, being able to add comments is a HUGE plus when programmatically generating documents (e.g., flagging which sections of a document were written by an LLM so a human can follow up and review those sections). I only see the need for this functionality increasing, and really hope to see this feature integrated into the main python-docx branch (@scanny)

@Cerebex

Cerebex commented Oct 28, 2024

Copy link
Copy Markdown

@scanny Any updates on merging footnote support into the library?

@beguelucas

beguelucas commented Nov 4, 2024 •

Copy link
Copy Markdown

does this feature of adding comments include adding hyperlinks inside comments?

i am currently using this approach to add hyperlinks to a run, which i took it from another github issue:

def add_hyperlink_into_run(
    paragraph: Paragraph,
    run: Run,
    url: str,
) -> None:
    runs = paragraph.runs
    for i in range(len(runs)):
        if runs[i].text == run.text:
            break

    # --- This gets access to the document.xml.rels file and gets a new relation id value ---
    part = paragraph.part  # type: ignore
    r_id = part.relate_to(  # type: ignore
        url,
        RELATIONSHIP_TYPE.HYPERLINK,
        is_external=True,
    )

    # --- Create the w:hyperlink tag and add needed values ---
    hyperlink = docx.oxml.shared.OxmlElement("w:hyperlink")  # type: ignore
    hyperlink.set(  # type: ignore
        qn("r:id"),
        r_id,
    )
    hyperlink.append(run._r)  # type: ignore
    paragraph._p.insert(i, hyperlink)  # type: ignore

does anyone have an insight on how to add a hyperlink to a subtring inside a comment created with bayoo-docx?

@scanny

scanny commented Jun 13, 2025

Copy link
Copy Markdown
Contributor

Comment support is being added in #1495 if you want to take a look. Should merge in a week or so.

@scanny

scanny commented Jun 16, 2025

Copy link
Copy Markdown
Contributor

Comment support was added to python-docx in release 1.2.0 and is available on PyPI.

This feature includes a way to create comments (document.add_comment()) and to access the comments that already exist (document.comments). Documentation for these features is available in the usual place: https://python-docx.readthedocs.io/en/latest/user/comments.html

Note this support does not include the ability to directly access the comment "reference", i.e. the range of text selected when the comment was created. It also does not include the threading or resolution features of comments. These may follow in a later release, but are not currently planned.

@BayooG closing this for now as it it as least partially implemented.

@scanny scanny closed this Jun 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.