Python / Excel:以编程方式closuresOffice Excel兼容性检查程序

我需要访问的数据文件正在以xlsx格式生成,但我需要它以xls格式来达到我的目的。

我可以使用win32com.client打开文件,但是保存不能完全完成,因为popup的兼容性检查器对话框会通过xlsx – > xls格式通知您丢失格式化/function。

这里的代码,目前不允许我保存文件执行挂起等待对话框closures,任何帮助将不胜感激:

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() 

我见过其他类似的post,提到我已经在这个脚本中设置的方法和属性。 我也修改了我的registry值ShowCompatDialog = 0。

MSDN 在Workbook.DoNotPromptForConvert属性上说:“true提示用户转换工作簿;否则为false”。

写下你的代码:

 wb.DoNotPromptForConvert = False 

更新:使用此Excel加载项解决此问题

作为参考:更改registry值正在工作,但价值每天重置在我开发的内部networking。无法编辑自己的registry值B / C我没有pipe理员权限这样做,以上的解决scheme是唯一的解决我的问题。