使用 Python 将 .doc 或 .docx 文档转换为 .odt 的最佳方法是什么?

时间:2021-06-17 15:55:16

标签: python docx file-conversion odt convertapi

我尝试了以下方法。涉及到convertapi库的使用。

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')                                                          ~       

虽然它有效,但我注意到自动章节编号发生了变化。原始文档有第 1 章到第 5 章。新的 odt 文档有第 1.1-1.5 章和第 2 章。

两个问题:是什么导致了这种情况,您能否推荐一种使用 Python 将文件从 .doc/.docx 转换为 .odt 的方法,而无需事后手动清理所有内容?谢谢。

0 个答案:

没有答案
相关问题