question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Merge multiple word documents?

See original GitHub issue

I’ve been playing around with this package to see if it’s possible to combine multiple word documents with a simple script. It seems like it should be possible given the objects, but I can’t find an intuitive way to do this.

Basically, I have a folder with .docx files like 01.docx, 02.docx, 03.docx etc. I’d just like to join these together in a single document as if I had “copy/pasted” each one in succession.

I’ve tried appending the paragraphs attribute of one to another, but this doesn’t seem to work, and add_paragraph only accepts a string, not a Paragraph object. Any idea on the best way to accomplish this?

ps: if this works then I am eternally grateful…this is a pretty nice package for people who are writing a dissertation, but whos advisor won’t let them use Latex 😉

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
DKWoodscommented, Oct 29, 2018

I created a fork of python-docx that provides easy access to images when r eading a DOCx file.  It might help you figure out what you need. https://github.com/DKWoods/python-docx

1reaction
Jesse-Backcommented, Mar 27, 2018

@xlhu19 It works actually, but header and footer has gone in the doc1 or doc2,

I would recommend

doc1 = docx.Document('1.docx')
doc2 = docx.Document('2.docx')
for element in doc2.element.body:
    doc1 .element.body.append(element)
doc1.save('new.docx')

that would be useful In case doc1 or doc2 has the same template

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Combine Word Documents Into a Single File
You can combine Word documents by using the Object button in the Insert tab. · Choose Text from File in the Object drop-down...
Read more >
How to Merge Two or More Microsoft Word Documents - Lifewire
Merge Different Versions of a Single Document · Go to the Review tab. · Select Compare. · In the drop-down menu, select Combine...
Read more >
How to combine Word documents - Adobe
Insert text from multiple Word files. · Launch Word and open the document that appears first in the combined file. · Select the...
Read more >
How to Combine Word Documents - How-To Geek
For most people, the quickest method for combining Word documents is to manually copy and paste them into one. This isn't the best...
Read more >
How to merge multiple documents and keep format in word?
Merge multiple documents into one document with Insert Text from File function · 1. Create a new Word document you will place the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found