[ACCEPTED]-How to generate Microsoft Word documents using Sphinx-documentation-generation

Accepted answer
Score: 15

The solution I use is singlehtml builder 4 like andho mentioned in the comment, then 3 convert the html to docx using pandoc. The 2 following sample assumes the generated html 1 would be located at _build/singlehtml/index.html

make singlehtml
cd _build/singlehtml/
pandoc -o index.docx index.html
Score: 8

There is a Sphinx extension for generating docx format (which 3 I haven't tested) and a newer one (which I also haven't 2 tested, but looks like it is more actively 1 maintained)

Score: 4

To convert files in restructured text to 10 MSdoc, I use rst2odt and next unoconv. Look next script:

rst2odt $1 $1.odt
unoconv -f doc $1.odt
rm $1.odt

With 9 rst2odt you can use your own stylesheet: unoconv comes 8 with OpenOffice and also allows to apply 7 an Open Office style (template) during the 6 conversion. Simply edit a converted document, change 5 styles, add headers and footers, save that 4 as an ODF Text Document Template (OTT) and 3 use this as part of the conversion, like:

unoconv -f doc -t template.ott $1.odt

to 2 use that template for various conversions 1 later on.

Score: 1

I realize this is an old question, but I 12 found that LibreOffice supports the following 11 way of doing conversion (assuming soffice.exe 10 is in your path):

soffice.exe --invisible --convert-to doc myInputFile.odt

Some things I have read 9 say to use the --headless option rather 8 than --invisible. Both seem to work on 7 Windows.

You can start with the rst2odt.py 6 script and then do the above to convert 5 to an MS Word document.

Here is a link with 4 additional start up options for LibreOffice: http://help.libreoffice.org/Common/Starting_the_Software_With_Parameters

Here 3 is a link with file types supported by OpenOffice 2 which, I believe, LibreOffice should also 1 support: http://wiki.services.openoffice.org/wiki/Framework/Article/Filter/FilterList_OOo_3_0

Score: 1

This answer is not a command line solution 8 and it is not obviously the best, but it 7 simply works for me and save my time. After 6 generating html file 1, you can open the 5 generated html with a browser and copy the 4 entire page (Crtl + a and Ctrl+ c) and then 3 run Microsoft Office(or use live version 2 if you don't have Microsoft Windows, like 1 me) and paste (Ctrl+v) to it.

Score: 0

The best option might be rst -> odt -> doc


Score: 0

This is a workaround using Calibre (https://calibre-ebook.com), which 5 includes a powerful converter. This worked 4 well and most of the formatting are preserved:

  • Generate epub output in Sphinx make epub
  • Import epub output into Calibre and then convert epub to docx using inbuilt ebook converter.

Answer 3 is too late for the original question, but 2 people looking at the same problem may find 1 this useful.

More Related questions