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.
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
I have to sort my paragraphs according to my needs.
I did it but now I can't overwrite to current document paragraphs
or add them to a new document.
Basically I have a list of paragraph objects that are in a different order and I need to put them
a document.
Is it possible?
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?
Great thanks in advance.
@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:
def direct_insert(doc_dest, doc_src):
for p in doc_src.paragraphs:
inserted_p = doc_dest._body._body._insert_p(p._p)
if p._p.get_or_add_pPr().numPr:
inserted_p.style = "ListNumber"
Partly inspired by
#217
.
By the way, it cross-document editing something a future priority?