#-*-代码: utf-8-*-
From win32com import client as WC
Import OS
密钥=“文档密码”
Def translate (input、output) :
#转换
word app=WC . dispatch(' word . application ')
tree :
Doc=worda (input,false,false,false,key)
Doc.saveas (filename=output,fileformat=4,encoding=' gb2312 ')
Doc。Close()
Print(input,“完成”)
Os.remove(input)
如果不希望# python在后续操作中以r方式读取txt并生成损坏的字符,则参数为4
Except:
Print(input,“密码错误”)
If _ _ name _ _==' _ _ main _ _ ' :
#docx文档物理路径
Path=r'C:\Users\docx '
密钥=“文档密码”
J=0
For file in os.listdir(path):
If '。doc' in file:
Name=('。docx')[0]
#输入文档的物理路径
input _ file=r ' c : \ users \ docx ' ' \ \ ' file
#输出文档物理路径
output _ file=r ' c : \ users \ txt \ ' ' \ \ ' name '。" txt "
Translate (input _ file、output _ file)
J=j 1
打印(j)
Else:continue