How can i convert html to word docx in python?

岁酱吖の 提交于 2019-12-21 22:31:16

问题


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.


回答1:


In Windows the easiest way will be to use MS Word using pywin32 plugin. Here is good answer with example code.

Using pypandoc:

output = pypandoc.convert(source='/path/to/file.html', format='html', to='docx', outputfile='/path/to/output.docx', extra_args=['-RTS'])

Read this for extra_args.



来源:https://stackoverflow.com/questions/42779184/how-can-i-convert-html-to-word-docx-in-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!