代码拉取完成,页面将自动刷新
同步操作将从 ypftest/python-word-process 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
"""
修改文档格式.docx转为.doc,并保存到docx上级目录中
"""
import pythoncom
import os
from docx import Document
from docx.opc.exceptions import PackageNotFoundError
# 从最后开始替换某字符串几次
def rreplace(s, old, new, occurrence):
li = s.rsplit(old, occurrence)
return new.join(li)
# 读取文件夹下的docx文件名列表
def docx_file_name(file_dir):
file_list = []
for root, dirs, files in os.walk(file_dir):
for file in files:
if os.path.splitext(file)[1] == '.docx':
file_list.append(os.path.join(root, file))
return file_list
# docx文件另存为doc
def docx_to_doc(docx_name):
pythoncom.CoInitialize()
try:
doc = Document(docx_name)
docx_name = rreplace(docx_name, "\\docx\\", "\\", 1)
doc.save(docx_name.replace(".docx", ".doc"))
except PackageNotFoundError:
pass
finally:
# 释放资源
pythoncom.CoUninitialize()
def main():
file_list = docx_file_name("D:\\文件处理\\2020.8.12-350篇足球")
print(len(file_list))
for file in file_list:
docx_to_doc(file)
if __name__ == '__main__':
main()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。