Python/Excel:以编程方式关闭Office Excel兼容性检查器 [英] Python / Excel : Turn off Office Excel Compatibility Checker Programmatically

查看:422
本文介绍了Python/Excel:以编程方式关闭Office Excel兼容性检查器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

具有我需要访问的数据的文件正在以xlsx格式生成,但出于我的目的,我需要将其以xls格式生成.

A file which has data I need to access is being generated in xlsx format yet I need it to be in xls format for my purpose.

我能够使用win32com.client打开文件,但是由于弹出兼容性检查器"对话框,因此无法完全完成保存,该对话框通过从xlsx-> xls格式显示来通知您丢失格式/功能.

I'm able to use win32com.client to open the file however the save cannot fully complete due to Compatibility Checker dialog pop up which notifies you of loss of formatting/features by going from a xlsx --> xls format.

以下是当前代码,由于执行挂起而需要等待对话框关闭,因此当前不允许我保存文件,非常感谢您的帮助:

Here's the code which currently doesn't allow me to save the file as execution hangs waiting for the dialog to close, any help would be much appreciated:

excel = win32com.client.Dispatch('Excel.Application')
excel.DisplayAlerts = False

in_file = u"C:\\Path\\to\\infile\\infile.xlsx"
out_file = u"C:\\Path\\to\\outfile\\outfile.xls"

wb = excel.Workbooks.Open(in_file)

wb.CheckCompatibility = False
wb.DoNotPromptForConvert = True

wb.SaveAs(out_file, FileFormat=56) #Execution hangs here
wb.Close()
excel.Quit()

我看过其他类似的文章,其中提到了我已经在此脚本中设置的方法和属性.我还已经将注册表值修改为ShowCompatDialog =0.

I've seen other similar posts which mention the methods and attributes I've already set in this script. I've also modified my the registry value to ShowCompatDialog = 0.

推荐答案

更新:使用此供参考:更改注册表值是可行的,但是每天都会在我所开发的内部网络上重置这些值.无法自己编辑注册表值b/c我没有管理员权限因此,上述解决方案是唯一解决我问题的方法.

For reference: Changing the registry value was working however the values were being reset daily on the internal network which I develop in. Without being able to edit the registry values myself b/c I don't possess the admin rights to do so, the above solution was the only thing that ended up solving my problem.

这篇关于Python/Excel:以编程方式关闭Office Excel兼容性检查器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆