Skip to content

low-level support for comments & footnotes #624

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 118 commits into
base: master
Choose a base branch
from

Conversation

BayooG
Copy link

@BayooG BayooG commented Mar 1, 2019

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
Copy link

leyiwang commented Mar 8, 2019

@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
Copy link
Author

BayooG commented Mar 8, 2019

@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
https://github.com/BayooG/bayoo-docx/tree/release/0.1.3

@BayooG
Copy link
Author

BayooG commented Jan 13, 2021

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

@Barsovski
Copy link

Barsovski commented Mar 18, 2021

@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
Copy link

verydemo commented Jul 14, 2021

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

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

@floyddcn
Copy link

@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 https://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

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

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
Copy link

Cayllen commented Mar 27, 2024

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

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

@rodolvbg
Copy link

rodolvbg commented Jun 4, 2024

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

@BayooG
Copy link
Author

BayooG commented Jun 6, 2024

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 https://github.com/BayooG/bayoo-docx

@wschlecht
Copy link

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
Copy link

Cerebex commented Oct 28, 2024

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

@beguelucas
Copy link

beguelucas commented Nov 4, 2024

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?

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.