Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i convert html to word docx in python?

import pypandoc
output = pypandoc.convert_file('file.html', 'docx', outputfile="file1.docx")
assert output == ""

It is generating new docx file but ignoring styles.

Can any one tell me how to generate new docx file with styles?

Thanks in advance for your answers.

like image 920
Jayasri Tanneru Avatar asked Mar 14 '17 06:03

Jayasri Tanneru


People also ask

Can you change HTML to Word?

You will need to use Microsoft Word to perform this process; luckily, Word will automatically convert an HTML document into its web page format when you open the HTML document in Word.


1 Answers

You can also use htmldocx in python 3.x:

from htmldocx import HtmlToDocx

new_parser = HtmlToDocx()
new_parser.parse_html_file("html_filename", "docx_filename")
#Files extensions not needed, but tolerated
like image 141
Synthase Avatar answered Oct 06 '22 11:10

Synthase