I have written a Python notebook .ipynb
in Visual Studio Code which includes code chunks and markdown chunks. I want to export this file into Microsoft Word .docx
format. It is easy to export it as .pdf
but how can I export it into .docx
?
Any brief solution?
3
Answers
A workaround would be to download the file as a pdf, then open the pdf with Word and ‘Save As’ docx.
As @I_K suggested, you can export it to a PDF file and then save it as a Word document. Since you have the tag python in your question, I assume that you are looking for a Python solution.
Here is an example Python script doing this (requires
nbconvert
,pywin32
, Pandoc and Microsoft Word installed):Please note that the script above (and below) is executing
nbconvert
in the command prompt. You could also use the packagenbconvert
in Python itself.Why do you want a Word document? PDF files are easier to distribute. Anyways, if you just need a PDF file, you can generate the file in your Command Prompt as well (without a script):
It still requires
nbconvert
and Pandoc installed.You can also export to an HTML file and then save it as a Word document. (not requiring Pandoc)
Following Python script executes and exports a Notebook file to HTML and then saves it as a Word document. Formatting is not very useful though.
Off-topic: Just some note if anyone comes across this answer and is wondering where to find the constants for the
FileFormat
parameter:convert .ipynb to .md (markdown) and using pandoc your_input.md -o your_output.docx