gpt4 book ai didi

python /Excel : Turn off Office Excel Compatibility Checker Programmatically

转载 作者:太空宇宙 更新时间:2023-11-04 02:58:57 24 4
gpt4 key购买 nike

一个包含我需要访问的数据的文件正在以 xlsx 格式生成,但出于我的目的,我需要它是 xls 格式。

我可以使用 win32com.client 打开文件,但是保存无法完全完成,因为会弹出兼容性检查器对话框,通知您从 xlsx --> xls 格式丢失格式/功能。

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

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。

最佳答案

MSDNon Workbook.DoNotPromptForConvert property :“如果提示用户转换工作簿,则为 true;否则为 false”。

写下你的代码:

wb.DoNotPromptForConvert = False

关于 python /Excel : Turn off Office Excel Compatibility Checker Programmatically,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41578066/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com