我在.docx 文件中填入了一些邮件合并字段, 现在我要我的脚本将保存的.docx 文件转换为.dotx 文件。 我正在使用 Python 3. 6 。
from __future__ import print_function
from mailmerge import MailMerge
from datetime import date
from docx import Document
from docx.opc.constants import CONTENT_TYPE as CT
import csv
import sys
import os
import numpy as np
import pandas as pd
# . . .
for i in range(0, numTemplates):
theTemplateName = templateNameCol[i]
theTemplateFileLocation = templateFileLocationCol[i]
template = theTemplateFileLocation
document = MailMerge(template)
print(document.get_merge_fields())
theOffice = officeCol[i]
theAddress = addressCol[i]
theSuite = suiteCol[i]
theCity = cityCol[i]
theState = stateCol[i]
theZip = zipCol[i]
thePhoneNum = phoneNumCol[i]
theFaxNum = faxNumCol[i]
document.merge(
Address = theAddress
)
document.write(r Usersmemailmergeproject est-output + str(i) + r .docx )
#do conversion here
底部是我想转换的地方, 正如你可以看到的, 我写了一个文件, 它就坐在一个文件夹里