yum install libreoffice-writer

安装 libreoffice

yum install libreoffice-headless
yum install libreoffice-writer
soffice --help
eg:
soffice --headless --convert-to docx /www/asd.doc
docx 目标类型
/www/asd.doc 文件路径
默认转换完成的文件会存在 /root/asd.docx

eg:指定目录
soffice --headless --convert-to docx --outdir /www /www/asd.doc
转换完成的文件会存在 /www/asd.docx

原文链接https://blog.csdn.net/qq_46081276/article/deta
不同于python调用win32api只能在Windows使用

import subprocess

output = subprocess.check_output(["soffice","--headless","--invisible","--convert-to","docx","path/test.doc","--outdir","path/test.docx"])
with open(file_name, mode=\'wb\') as f:
f.write(res.body)
import subprocess
subprocess.check_output(
["soffice", "--headless", "--invisible", "--convert-to", "docx", file_name, "--outdir",
"/tmp"])
x_path = f"/tmp/{file_name}x"
os.unlink(file_name)
os.unlink(x_path)