思路:

1、需要用到libreoffice库。
2、然后使用python的subprocess执行转化命令。
python代码如下:

doc_path = './test.doc'  # 你的doc原文件
target_format = 'docx'  # 转化为docx格式
output_directory = './'  # 转化后的docx文件保存到的目录

subprocess.call(
    [
        "soffice",
        "--headless",
        "--convert-to",
        target_format,
        "--outdir",
        output_directory,
        doc_path,
    ],
)

libreoffice安装

ubuntu下安装:

apt-get install libreoffice -y
Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐