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)