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
{{ message }}
Repository navigation
Copy paragraphs elements from one document to another. #182
Accomplishing this in the general case is tricky. However, if your paragraphs are simple in content, its possible to get it done with a simple approach.
There are two main approaches:
Copy the content paragraph by paragraph, then write new paragraphs in the new document.
Use deepcopy() to copy the lxml objects and insert them into the document at the lxml level.
With the first approach you'll need to go down to the run level to read and construct the new paragraphs, otherwise all text formatting will be lost.
@scanny I encounter a similar problem. I need to copy a document's whole content including pictures, paragraphs, page breakers to another document. The second document need to be looked the same as the first one.
Can you explain in detail about the two approaches:
As for the first one, how can it deal with pictures?
As for the second one, how can I access lxml objects of the source document?
@scanny, @downtown12, I have tried the following code and it works (preserving simple styles), but as it was stripping the list tags, I had to make an extremely ugly hack:
I'd say it's unlikely to appear soon unless someone decides to contribute it or sponsor it. It's a challenging feature set because a general case solution entails reconciling the styles across the two documents.
Activity
scanny commentedon Jun 1, 2015
Accomplishing this in the general case is tricky. However, if your paragraphs are simple in content, its possible to get it done with a simple approach.
There are two main approaches:
With the first approach you'll need to go down to the run level to read and construct the new paragraphs, otherwise all text formatting will be lost.
downtown12 commentedon Jul 6, 2015
@scanny I encounter a similar problem. I need to copy a document's whole content including pictures, paragraphs, page breakers to another document. The second document need to be looked the same as the first one.
Can you explain in detail about the two approaches:
Great thanks in advance.
berezovskyi commentedon Nov 17, 2015
@scanny, @downtown12, I have tried the following code and it works (preserving simple styles), but as it was stripping the list tags, I had to make an extremely ugly hack:
Partly inspired by #217.
By the way, it cross-document editing something a future priority?
scanny commentedon Nov 18, 2015
I'd say it's unlikely to appear soon unless someone decides to contribute it or sponsor it. It's a challenging feature set because a general case solution entails reconciling the styles across the two documents.
berezovskyi commentedon Nov 20, 2015
@scanny thanks for an amazing work you've already done!
Thebee23 commentedon Sep 6, 2017
How can i extract numbering of multilevel list from a docx using python..
scanny commentedon May 14, 2026
Closed as inactive.