使用带带弟docr进行图片解析 识别错误 如何提高识别精度
看了半天文档没看懂
q
python提供了win32com模块,其中的SaveAs方法可以代替人手批量将文件另存为我们需要的格式。
win32com包含在pypiwin32模块中,只需安装pypiwin32模块即可:
pip install pypiwin32
下面的代码将指定目录下的doc文件转换为docx格式,并放在该目录的temp_dir下面:
from win32com import client as wc # 导入模块
from pathlib import Path
import os
import shutil
doc_path = r"E:\tmp\答疑整理"
temp_dir = "temp"
if os.path.exists(f"{doc_path}/{temp_dir}"):
shutil.rmtree(f"{doc_path}/{temp_dir}")
os.mkdir(f"{doc_path}/{temp_dir}")
word = wc.Dispatch("Word.Application") # 打开word应用程序
try:
for filename in Path(doc_path).glob("*.doc"):
file = str(filename)
dest_name = str(filename.parent/f"{temp_dir}"/str(filename.name))+"x"
print(file, dest_name)
doc = word.Documents.Open(file) # 打开word文件
doc.SaveAs(dest_name, 12) # 另存为后缀为".docx"的文件,其中参数12指docx文件
finally:
word.Quit()
运行结果:
转换得到的文件: