F
F
fiddle_stisk2020-11-14 21:22:20
go
fiddle_stisk, 2020-11-14 21:22:20

How can I create a docx file in golang?

I need to create a docx file and add images there
I know that a docx file is xml files packed in a zip archive
The problem is how to generate these xml files so that later I can zip them and get a regular docx file

I would like from scratch write something of your own, unless of course it’s not too difficult
. Please tell me in which direction to move, I couldn’t find something similar on the Internet

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dvoeglazyi, 2021-11-13
@dvoeglazyi

The complexity depends on the functionality that is required there. Potentially in these formats (DOCX, XLSX, ...) it is very large (and sometimes legacy). In general, it is possible, from scratch it is difficult, I once found some very sluggish documentation on these formats. Something like a huge list of XML tags and attributes with almost no description of their purpose and how they work.
You can see how it's done in free libs. They exist, although sometimes they are too situational, sometimes, on the contrary, they are too universal, and therefore complex. There are template engines (templater) - you can look into them.
You can manually change something in the DOCX document, then unzip it and see what changes in the XML.
Further - by analogy, change to Golang, then archive - the scheme is working. BUT, there may be compatibility issues, because. Microsoft Word can do it one way, LibreOffice Writer another way, and so on.
Files that do not need to be changed - you can store their data (and names) as a constant. Which should change - generate via encoding/xml or string concatenation.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question