You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
How can I copy the paragraphs of one document to another document or e.g. into a table cell?
This was my current code, but always something is missing. Now the bullet list styles and the hyperlinks are gone.
@staticmethoddefdocx_copy_paragraph(source_paragraph: Paragraph, target_paragraph: Paragraph) ->None:
""" Copy the content and formatting from source_paragraph to target_paragraph. Args: source_paragraph (Paragraph): The source paragraph to copy from. target_paragraph (Paragraph): The target paragraph to copy to. """# Copy each run (text with formatting) from the source paragraph# to the target paragraph.forruninsource_paragraph.runs:
target_run=target_paragraph.add_run(run.text, run.style)
source_run_property=run._r.get_or_add_rPr() # pylint: disable=protected-accessnew_run_property=copy.deepcopy(source_run_property)
target_run._r.replace(target_run._r.get_or_add_rPr(), new_run_property) # pylint: disable=protected-access
Great question, its likely because one of the features implemented doesnt quite do it the way the library expects and therefore it fails to read it out in the run tag. I can take a look and try some things but no promises
Oh yes, it looks like. There in the repository are many other similar issues too. Hmm ... I will re-think about my use case and whether I can workaround the need of copying paragraphs. Murphys law ... everything works, but just this little last piece ... :-)
Activity
Skelmis commentedon Oct 21, 2025
Great question, its likely because one of the features implemented doesnt quite do it the way the library expects and therefore it fails to read it out in the run tag. I can take a look and try some things but no promises
Skelmis commentedon Oct 21, 2025
This seems like a complicated problem, see here for an example.
Perhaps also take a look at this? https://github.com/darkvisiontech/docxcompose/tree/master
BlueAndi commentedon Oct 21, 2025
Oh yes, it looks like. There in the repository are many other similar issues too. Hmm ... I will re-think about my use case and whether I can workaround the need of copying paragraphs. Murphys law ... everything works, but just this little last piece ... :-)
I will have a look to docxcompose, thanks.