如何使用python将word文件保存为dotx格式?

问题描述 投票:0回答:1

在我的工作中,我需要为带有一些典型数据的专用程序创建很多 dotx 文件。我尝试使用流行的库,如 docxtpl 或 python-docx,但据我了解,它们不支持使用 dotx 文件。是否有任何免费的库或 docxtpl 插件可以解决我的问题?

从 docx 到 dotx 的简单转换器也适合我。我尝试使用 Aspose.Words 库,但它不是免费的并且会创建水印。

python ms-word converters docx
1个回答
0
投票

您可以使用 spire.doc 模块来实现此目的。

根据您的操作系统(windows / linux)从这里下载 spire.doc。这是一个轮文件。安装程序是:

cd <path/to/file's/parent/directory>
#assuming you use python3
pip3 install <wheel_file_name_with extension>

用途:

from spire.doc import *
from spire.doc.common import *

ip_file = '<ip_file_with_path_and_extension>'
op_file = 'xxxx.dotx'

doc = Document()
doc.LoadFromFile(ip_file)

doc.SaveToFile(op_file, FileFormat.Dotx)

doc.Close()
© www.soinside.com 2019 - 2024. All rights reserved.