Gehaxelt
Gehaxelt

Reputation: 81

How to merge office documents?

The situation is a handful office documents in different formats and with different layouts/contents:

I cannot find a good way to merge all documents of either format, because there is no commandline option/tool [0,1,2] or the layout is messed up [3], e.g. ooo_cat.

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.

What is the best way to smoothly merge several documents programmatically/linux commandline?

[0] https://ask.libreoffice.org/en/question/19222/how-to-merge-multiple-documents-into-single-merged-document/

[1] https://forum.openoffice.org/en/forum/viewtopic.php?f=7&t=57435

[2] https://support.microsoft.com/en-us/help/2665750/how-to-merge-multiple-word-documents-into-one---eeekb

[3] https://askubuntu.com/questions/482277/how-to-merge-odt-documents-from-the-command-line

Upvotes: 1

Views: 1580

Answers (1)

Jim K
Jim K

Reputation: 13790

  1. Start LibreOffice listening with --headless.
  2. Use Python interactively in a shell and start with import uno. Or this can be done with a Python script. A good tutorial is at http://christopher5106.github.io/office/2015/12/06/openoffice-libreoffice-automate-your-office-tasks-with-python-macros.html.
  3. Based on link [1] in the question, call Insert -> Document like this recorded Basic code.
dim args(1) as new com.sun.star.beans.PropertyValue
args(0).Name = "Name"
args(0).Value = "file:///path/to/the_document.odt"
args(1).Name = "Filter"
args(1).Value = "writer8"
dispatcher.executeDispatch(document, ".uno:InsertDoc", "", 0, args())

Upvotes: 1

Related Questions