4
$\begingroup$

What would be a practical way to convert a Jupyter Notebook to a Word document (.doc) ? I am asking this in a professional context, so I'd like to avoid manual solutions, do it in an efficient way (fast), avoid third parties... etc. Something that works like Rmarkdown to produce .doc would be very welcome.

$\endgroup$
1

2 Answers 2

4
$\begingroup$

The easiest way is probably using a method similarly to what is described in this answer, that is, convert the notebook to markdown and then use any of the tools available (such as Pandoc) to convert the markdown to a Word document.

$\endgroup$
1
  • $\begingroup$ I did see that question (and answer), but couldn't find a way to convert .md from python. It appears that pypandoc would do the trick. Thanks. $\endgroup$ Commented Jan 24, 2020 at 21:51
3
+100
$\begingroup$

Jupyter Notebooks For Assessment – Export as Word (.docx) Extension.

The only challenge with this post is that it's a bit confusing and cumbersome since it requires you to deal with an extension. Despite that, in the code provided in the post one only needs two commands to run in order to convert the jupyter notebook file (ipynb) to word (docx).

Before that, make sure you have jupyter nbconvert and pandoc set up

To convert the jupyter notebook to word, first, we need to convert the notebook to html. You can perform these commands from cmd, powershell or terminal on mac.

jupyter nbconvert --to html your_notebook_name.ipynb

After execution will create HTML version of your notebook and will save it in the current working directory. You will see one html file will be added into the current directory with your_notebook_name.html name

(your_notebook_name.ipynb --> your_notebook_name.html)

Then we need to convert html file generated to word (docx)

pandoc -s my_notebook.html -o my_notebook.docx
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.