How to generate Microsoft Word documents using Sphinx

14,176

Solution 1

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

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

Solution 2

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

Solution 3

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

#!/bin/sh
rst2odt $1 $1.odt
unoconv -f doc $1.odt
rm $1.odt

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

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

to use that template for various conversions later on.

Solution 4

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

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

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

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

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

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

Share:
14,176

Related videos on Youtube

Andrea Francia
Author by

Andrea Francia

Updated on April 15, 2022

Comments

  • Andrea Francia
    Andrea Francia about 2 years

    Sphinx supports a few output formats:

    • Multiple HTML files (with html or dirhtml)
    • Latex which is useful for creating .pdf or .ps
    • text

    How can I obtain output in a Microsoft Word file instead?

    With another doc generator I managed to generate a single html output file and then convert it to Microsoft Word format using the Word application.

    Unfortunately I don't know a way to generate either Word or the HTML single-page format.

    • andho
      andho over 11 years
      make singlehtml to generate single html file.
  • David Fraser
    David Fraser over 11 years
    I haven't tested these, but I'm adding them here as they're clearly produced to solve the problem the questioner had, are more direct and less convoluted than the alternatives currently proposed, and following the links and ideas here probably won't lead you to them...
  • David Fraser
    David Fraser almost 10 years
    Please feedback if you've used this successfully - and which one was best!
  • ankostis
    ankostis over 9 years
    But that does not handle the full sphinx features, just RsT ones, correct?
  • ffleandro
    ffleandro almost 9 years
    I tried using the second one but couldn't install it's requirements.
  • Harry Yoo
    Harry Yoo over 5 years
    In my case, pandoc removed some styles, especially code blocks. So, I opened the single doc in a browser and grep entire document (ctrl-a) and copy-pasted into word. This preserves all the styling I had.
  • Aziz Alto
    Aziz Alto almost 5 years
    Thanks! this answer deserves the green badge.
  • Can H. Tartanoglu
    Can H. Tartanoglu about 3 years
    The OP asked explicitly for a path from Sphinx to docx, not from .rst files. Sphinx projects support other formats than just ReStructured Text.
  • Can H. Tartanoglu
    Can H. Tartanoglu about 3 years
    Most certainly the fastest way.
  • Can H. Tartanoglu
    Can H. Tartanoglu about 3 years
    Nothing to do with Sphinx.