[英]Opening corrupted Excel file with Python via COM interface
I'm trying to open an excel file using COM interface in Python. 我正在尝试使用Python中的COM接口打开一个excel文件。 Normally it's easy but this time I have problem with opening the file that is corrupted.
通常,这很容易,但是这次我遇到了打开损坏的文件的问题。 Error I get looks like this (partially in Polish):
错误我得到这样的样子(部分是波兰语):
com_error: (-2147352567, 'Wyst\xb9pi\xb3 wyj\xb9tek.', (0, u'Microsoft Excel', u'Open method of Workbooks class failed', u'xlmain11.chm', 0, -2146827284), None)
I coped with such problem previously in VBA by using additional parameter corruptload:=xlRepairFile
in Open method. 我以前在VBA中通过在Open方法中使用其他参数
corruptload:=xlRepairFile
来解决了此类问题。 Do you have any idea how to do it in Python? 您知道如何在Python中执行此操作吗?
Below code doesn't work. 下面的代码不起作用。
excel.Workbooks.Open(latest_file, CorruptLoad = "xlRepairFile")
Try: 尝试:
excel.Workbooks.Open(latest_file, CorruptLoad=1)
There's an example here of someone getting it working. 这里有一个使人正常工作的例子。 Their full example is:
他们的完整例子是:
xlApp = Dispatch("Excel.Application")
wb1=xlApp.Workbooks.Open(inputfile,ReadOnly=1,CorruptLoad=1)
xlApp.SendKeys("{Enter}",Wait=1)
xlApp.DisplayAlerts = 0
xlApp.Quit()
del xlApp
They also note: 他们还指出:
The DisplayAlerts is needed to prevent Excel from asking if it should save a file that was opened as ReadOnly in the first place.
需要使用DisplayAlerts来防止Excel询问是否应首先保存以ReadOnly打开的文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.