0

I've tried to convert docx file to html by using python libraries docx and mammoth.

I've achieved to convert a file from docx to html at basic level.

However, I couldn't find a way to properly take the docx elements style like alignment, color or font-size etc to the html output.

doc = docx.Document("hello world.docx")
print(doc.paragraphs[0].alignment)

I can reach some style properties with the codes like above. It gives me an output like

CENTER (1)

or

RIGHT (2) 

Is there any module or package which provides a maping .docx styles to css code, when converting the docs to html?

selimhan
  • 13
  • 4
  • Please be more clear what your actual question is. You state that you need to map docx style to html. This seems pretty much neccessary to me. Are you asking weather there already exists such mapping? If so, please make that clear in your question. – Felix Jun 10 '22 at 13:00
  • I've edited and tried to make it more clear. I basically need to convert docx to html by using some proper python packages which protects the style of docx when making this conversion. – selimhan Jun 10 '22 at 13:06
  • What you have put here ("So, I need to use a mapping solution that will take the docx style to html.") is a statement wich is completely true. It is thus far from beeing a question. A question could for example look like "Is there any module or database which provides a maping from the .docx styles to html?" – Felix Jun 10 '22 at 13:10
  • Now I understand the point. I didn't realized it will look more like a self-advice rather than a question although it passes from the same door in my native language. I'll edit again. – selimhan Jun 10 '22 at 13:16
  • Did you check out [this blog post](https://stackabuse.com/how-to-convert-docx-to-html-with-python-mammoth/)? – Felix Jun 10 '22 at 13:18
  • Yes, I've read that post. Its very useful but not enough to solve style mapping issue. – selimhan Jun 10 '22 at 13:34

0 Answers0