I have few word files that each have specific content. I would like for a snippet that show me or help me to figure out how to combine the word files into one file, while using Python
rng = self.doc.Range(0, 0)
for d in data:
docstart = d.wordDoc.Content.Start
self.word.Visible = True
docend = d.wordDoc.Content.End - 1
location = d.wordDoc.Range(docstart, docend).Copy()
If your needs are simple, something like this might work:
source_document = Document('source.docx') target_document = Document() for paragraph in source_document.paragraphs: text = paragraph.text target_document.add_paragraph(text)
There are additional things you can do, but that should get you started.
It turns out that copying content from one Word file to another is quite complex in the general case, involving things like reconciling styles present in the source document that may be conflicting in the target document for example. So it's not a feature we're likely to be adding in the next year, say.