
Ask HN: How to merge office documents? - gehaxelt
Hello HN community,<p>I struggle to solve the problem in an acceptable way, so I wanted to ask if HN has any other ideas&#x2F;tips&#x2F;tricks? Thanks in advance :)<p>The situation is a handful office documents in different formats and with different layouts&#x2F;contents:<p>- {A,B,C}.odt<p>- {D,E,F}.doc<p>- {G,H,I}.docx<p>I cannot find a good way to merge all documents of either format, because there is no commandline option&#x2F;tool [0,1,2] or the layout is messed up [3], e.g. ooo_cat.<p>The expected result should be one single file that contains the contents of the other three files without breaking the layout or other unwanted side effects. Merging the base template files into one big template is unfortunately not an option.<p>Questions:<p>Q1) What is the best way to smoothly merge several documents [programmatically&#x2F;cmd line]?<p>Q2) The documents are generated using the process below. What is HN&#x27;s way to generate nice-looking office documents with dynamic data? (Except programming&#x2F;building the whole document and elements from scratch?)<p>A document is based on a .fodt [4] template with Jinja2 templating-blocks. The generation process is:<p>1.) Read the .fodt template file<p>2.) Populate content with the Jinja2 engine and save the &quot;rendered&quot; .fodt file<p>3.) Use cmd-line libreoffice to convert the .fodt file to .odt&#x2F;.doc&#x2F;.docx<p>[0] https:&#x2F;&#x2F;ask.libreoffice.org&#x2F;en&#x2F;question&#x2F;19222&#x2F;how-to-merge-multiple-documents-into-single-merged-document&#x2F;<p>[1] https:&#x2F;&#x2F;forum.openoffice.org&#x2F;en&#x2F;forum&#x2F;viewtopic.php?f=7&amp;t=57435<p>[2] https:&#x2F;&#x2F;support.microsoft.com&#x2F;en-us&#x2F;help&#x2F;2665750&#x2F;how-to-merge-multiple-word-documents-into-one---eeekb<p>[3] https:&#x2F;&#x2F;askubuntu.com&#x2F;questions&#x2F;482277&#x2F;how-to-merge-odt-documents-from-the-command-line<p>[4] https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;OpenDocument_technical_specification<p>EDIT: Formatting
======
Declanomous
This is something I did a lot using VBA. I'm not sure how to do it with open
document format, but it's really easy using VBA. The MS Word object has a
method to combine documents.

I did something similar to what I think you are trying to do. I basically
merged data into several different documents, and then I combined those
documents into a single document. I could dig up the code if you think that is
something you'd be interested in, but I'm not entirely sure what your end goal
is.

------
gotorazor
I don't think there is one.

As someone who works on docx documents all the time, even the method to merge
them together is often problematic.

If you have the original data, you should probably try to regenerate them all
again since the build chain is clean.

Of course, if you did manage this process, let me know. It would save me time
as well.

~~~
gehaxelt
Hey,

I cross-posted the question on SO [0] and got an interesting answer!

[0] [https://stackoverflow.com/questions/47351447/how-to-merge-
of...](https://stackoverflow.com/questions/47351447/how-to-merge-office-
documents/47356889#47356889)

