I am trying to convert a html to doc or docx. I used some of the available php classes but the results are not good. I wonder if I can convert a html file to doc using some office software like LibreOffice or OpenOffice?

LibreOffice (AbiWord) "converts" html to a doc file but without formatting. I mean I see the html sourcecode when I open the doc file.

abiword --plugin AbiCommand
convert /home/qqq/test/test.htm /home/qqq/test/test.doc doc

And with openOffice, nothing happens..:

soffice --headless --convert-to doc:DOC  /home/qqq/test/test.htm

I have to press ctrl+c to get back to the console.

Any Ideas how to convert html to doc? I can open the html in the desktop version of these two apps and save as doc but it seems not to work in the console version.

  • IIRC, libre/openoffice won't work unless there's only one instance of it open. That might be your problem with the second command. – evilsoup Sep 29 '14 at 11:38
  • pandoc does this quite well, but you specifically limited your question to OO / LO so I'm not putting this an an answer... – Jan Sep 29 '14 at 15:06
  • @Jan - installed and tested. It does not work. It renames the html to docx but without actually converting it. :( I am open for any solution. – MilMike Sep 29 '14 at 15:48
  • Just re-checked, works as supposed to: pandoc -s -r html page.html -o output.docx... It's a very complex program and you have to get used tto it though. – Jan Sep 29 '14 at 15:53
  • if you open the output.docx in a text editor you will see that it is just the html sourcecode. And the sourcecode is also broken by pandoc. The html in the docx is not the same as my source html - the result looks terrible. – MilMike Sep 29 '14 at 18:02

This is a very late response, but I hope it helps a few people.

LibreOffice makes use of filters

In the below code example (converting HTML to PDF, for example), you'll notice secondary optional arguments, such as --infilter=writerglobal8_HTML and :writer_web_pdf_Export:

soffice --headless --infilter=writerglobal8_HTML  --convert-to pdf:writer_web_pdf_Export --outdir /SomeFolder/Output /SomeFolder/Example.html

These are known as 'filters'. It's equivalent to the subcategories of individual filetypes. For example, a .doc could be a Microsoft Office 95 document, or a 2003 Document. It basically gives LibreOffice a clue as to what format the file is in.

There's two types of filter, an in filter (which is basically 'what sub-format is the incoming file') and an out filter (what format is the outgoing, IE exported, file in).

In your case, valid DOC filters include (where spaces are included, you'd likely need to use quotations, but I often find quotes don't work, so your mileage may vary):

MS WinWord 5
MS WinWord 6.0
MS Word 2003 XML      
MS Word 2007 XML      
MS Word 2007 XML Template      
MS Word 2007 XML VBA      
MS Word 95      
MS Word 95 Vorlage      
MS Word 97      
MS Word 97 Vorlage      

You can work out some of the file filters from the (somewhat disorganised) .ODS sheet LibreOffice supplies found here.


This may be a dumb solution, or idiocratic to a few particulars of the HTML files I'm using, but try renaming the file with a .docx extension. I've been able to open them as "word" files and subsequently save them as word files.

  • Well, if it works it works. – Insane Oct 29 '15 at 0:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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