What's the best way to convert a .doc or .docx document to .odt using Python?

595 Views Asked by At

I've tried the following. It involves the use of the convertapi library.

import convertapi                                                                                                       
import os                                                                                                               
import tempfile                                                                                                                                                                                                                                                                                                                                                         

convertapi.api_secret = 'my_secret'                                                                              
print('Converting from .doc(x) to .odt')                                                                                
odt_result = convertapi.convert('odt', { 'File': '/mnt/c/Users/username/Documents/TGMC.docx' })                                 
odt_result.file.save('/mnt/c/Users/fvsha/Documents/TGMC2.odt')                                                          ~       

While it worked, I noticed a change in the automatic chapter numbering. The original document had chapters 1 through 5. The new odt document had chapters 1.1-1.5 followed by chapter 2.

Two questions: What caused this and could you recommend a way to convert the file from .doc/.docx to .odt using Python without having to manually clean up everything afterwards? Thank you.

0

There are 0 best solutions below