Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x Python comtypes使用密码取消打开文件_Python 3.x_Comtypes - Fatal编程技术网

Python 3.x Python comtypes使用密码取消打开文件

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

我有一个python脚本,其中我使用comtypes处理ms office文件。但是,我需要处理的某些文档有密码,这会导致我的脚本在等待密码提示输入时,在批量触发脚本时被卡住吗

如果以编程方式打开文件时有密码,是否有取消打开文件的选项

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?