Python 3.x Python comtypes使用密码取消打开文件
我有一个python脚本,其中我使用comtypes处理ms office文件。但是,我需要处理的某些文档有密码,这会导致我的脚本在等待密码提示输入时,在批量触发脚本时被卡住吗 如果以编程方式打开文件时有密码,是否有取消打开文件的选项Python 3.x Python comtypes使用密码取消打开文件,python-3.x,comtypes,Python 3.x,Comtypes,我有一个python脚本,其中我使用comtypes处理ms office文件。但是,我需要处理的某些文档有密码,这会导致我的脚本在等待密码提示输入时,在批量触发脚本时被卡住吗 如果以编程方式打开文件时有密码,是否有取消打开文件的选项 import comtypes word = comtypes.client.CreateObject('Word.Application') doc = word.Documents.Open(src_filename) 您可以使用PasswordDo
import comtypes
word = comtypes.client.CreateObject('Word.Application')
doc = word.Documents.Open(src_filename)
您可以使用PasswordDocument关键字参数:
doc = word.Documents.Open(r"d:\test.docx",PasswordDocument="test")
使用python3.6测试的整个代码段:
from comtypes.client import CreateObject
word = CreateObject('Word.Application')
word.visible = True
doc = word.Documents.Open(r"d:\test.docx",PasswordDocument="test")
伟大的这对我来说很有用,并将其封装到try-catch块中,以继续处理其他文件的循环PasswordDocument关键字是否也适用于其他office文档,如ppt和msg?