How to generate Microsoft Word documents using Sphinx
Asked Answered
B

8

28

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.

Bifacial answered 13/5, 2009 at 15:13 Comment(1)
make singlehtml to generate single html file.Burnejones
N
16

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
Natality answered 6/12, 2017 at 12:0 Comment(3)
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.Ailey
Thanks! this answer deserves the green badge.Hepler
Most certainly the fastest way.Philbin
M
8

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)

Mcclenon answered 13/3, 2013 at 14:47 Comment(3)
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...Mcclenon
Please feedback if you've used this successfully - and which one was best!Mcclenon
I tried using the second one but couldn't install it's requirements.Campground
T
4

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.

Terrilyn answered 11/1, 2011 at 22:13 Comment(2)
But that does not handle the full sphinx features, just RsT ones, correct?Sadden
Nothing to do with Sphinx.Philbin
K
1

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

Krebs answered 26/4, 2012 at 17:47 Comment(1)
Nothing to do with Sphinx.Swagerty
H
1

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

Haines answered 14/7, 2016 at 3:58 Comment(0)
H
0

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

Highlight answered 25/8, 2009 at 13:34 Comment(1)
The OP asked explicitly for a path from Sphinx to docx, not from .rst files. Sphinx projects support other formats than just ReStructured Text.Philbin
N
0

This is a workaround using Calibre (https://calibre-ebook.com), which includes a powerful converter. This worked 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 is too late for the original question, but people looking at the same problem may find this useful.

Nikola answered 27/10, 2017 at 8:1 Comment(0)
D
-5

I don't now what Sphinx is, but you could create a rtf file or html file or something similar.

See the following blogpost for more information/approaches : OFFICE AUTOMATION

and from there : How to use ASP to generate a Rich Text Format (RTF) document to stream to Microsoft Word

This article describes how you can generate Rich Text Format (RTF) files with ASP script and then stream those files to Microsoft Word. This technique provides an alternative to server-side Automation of Microsoft Word for run-time document generation.

You don't use ASP script (who does :-) ), but for the idea.

Dingus answered 13/5, 2009 at 15:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.