How to insert an object into a word document with go

(Chris) #1

I hope to insert an embedded object(another .docx file) into a .docx file. Is there any package that support this?

(catacombs) #2

Must it be a Word document? You can easily write output to a .txt file.

(Chris) #3

@catacombs, thank you for your reply!
Yes, the request from my manager is to insert one docx file into another docx file. Since we did this way manually before, now we hope to automate the same process. Do you have any idea?

(George Calianu) #4

I didn’t tried but at first sight are some resources on the internet like this one

(catacombs) #5

@xxn, I’m still not sure what you mean by “inserting one docx into another docx.” What is the use case? Are you simply copying text from one file to another?

(Chris) #6

Not copy “text” from one file to another. The use case is copying one .docx file(as an object) to the text of another .docx file.

(catacombs) #7

Isn’t that the same as cp file1.txt file2.txt?

(George Calianu) #8

Documents (docx) [Word]

(Chris) #9

Sorry for late reply. I tried all the examples for document in unidoc/unioffice. But failed to find a method which I want.

(Chris) #10

Not the same as “cp file1.txt file2.txt”.

Actually, I use windows.

  • Right-click word1.docx and select “copy”.
  • Double-click word2.docx to open it.
  • Put the cursor in the text of word2.docx. And right-click and select paste.
    Then word1.docx will be inserted into word2.docx as an object.
    like this:

(George Calianu) #11

I don’t know if there is an explicit concatenate function but I think you can read the content of one document and insert it at the end of the other.

(Norbert Melzer) #12

This is something totally different.

Embedded objects in in .docx is more like what the name says. An object that is fully embedded. Just think of it, as an image in HTML that is provided base64 encoded inline rather than the regular HTTP-URL to download the image drom.