How to create a word document in docx form with terminal

Solution 1:

According to this thread over at Unix & Linux, you can use Pandoc.

From skimming the documentation, I think you could use it like:

echo "Hello" | pandoc -o out.docx

Then out.docx will be a docx file with "Hello" in it.


As well, I found this Python module: python-docx

Solution 2:

LibreOffice comes with a command-line tool called soffice which has libreoffice pointing to it, this tool has a --convert-to option which lets you easily convert files in the same way the GUI program does, e.g.:

libreoffice --convert-to docx file.txt

This creates the file file.docx in Office Open XML Text format in the current directory.

Usage example

$ echo some text > file.txt
$ libreoffice --convert-to docx file.txt 

convert /home/dessert/file.txt -> /home/dessert/file.docx using filter : Office Open XML Text
$ file file.docx 
file.docx: Microsoft OOXML