-2

I'd need to convert a .docx file with colored words into html. I've tried the mammoth library but the colors are lost. How could I achieve my goal?

macropod
  • 12,757
  • 2
  • 9
  • 21
Javi Torre
  • 724
  • 8
  • 23

1 Answers1

4
import win32com.client
doc = win32com.client.GetObject("demo.docx")
doc.SaveAs (FileName="hey.html", FileFormat=8)
doc.Close ()
  • Actually I'd need to save the html code into a txt file. Would that be possible? – Javi Torre Mar 12 '21 at 18:00
  • 1
    I don't understand. The OP says docx to Html. If you need to save an html code to txt, Use [BeautifulSoup](https://www.crummy.com/software/BeautifulSoup/bs4/doc/). – FugitiveMemories Mar 13 '21 at 05:56
  • I would first need to convert the docx file to an html variable and then deploy that variable into a txt file. Can I do those steps with beautiful soup? – Javi Torre Mar 13 '21 at 08:29
  • Yes, indeed. It would have been easier for everyone if you had given some context to your problem. `soup = BeautifulSoup(open("path_to_hey.html"), "html.parser")` And then read [here](https://stackoverflow.com/questions/14694482/converting-html-to-text-with-python) – FugitiveMemories Mar 13 '21 at 08:41