openpyxl-加载工作簿并保存,打开带有错误消息的已保存文件 [英] openpyxl - load the workbook and save , open saved file with error message
问题描述
打开文件时出现错误消息:
Error Message while opening the file:
Excel在zz.xlsx中发现了不可读的内容.是否要恢复工作簿的内容?如果您信任工作簿的来源,请单击是".
Excel found unreadable content in zz.xlsx. Do you want to recover the contents of the work book?If you trust the source of the workbook,click Yes.
如果我说是",则会弹出修复zz.xlxs".
If I say "Yes" got "Repairs to zz.xlxs" pop up shows.
任何人都可以帮助我. excel的哪种格式可能导致了这种情况. 当我尝试示例工作簿而不进行任何格式化时,它工作正常.
Could any one please help me. What format of the excel could have caused this. As i tried sample workbook without any formatting it work fine.
我的代码:
from openpyxl import Workbook
from openpyxl import load_workbook
#open existing workbook
wb = load_workbook(filename = 'xx.xlsx')
wb.save('zz.xlsx')
感谢您的帮助. 谢谢!
Appreciate your help. Thanks!
推荐答案
首先检查您的文件* .xlsx格式是"Office Open XML"还是"Microsoft Excel 2007/2010/2013中的XML". 如果是这种格式,则可以正常运行.
First of all check if your file *.xlsx format is "Office Open XML" or "XML from Microsoft Excel 2007/2010/2013". If this is the format it will work OK.
默认情况下,文件未保存为模板,您可以定义它以尝试引起此错误. Openpyxl文档
By default the file is not saved as a template, you can define it to try if this is causing the error. Openpyxl documentation
wb = load_workbook('document.xlsx')
wb.save('document_template.xltx', as_template=False)
这篇关于openpyxl-加载工作簿并保存,打开带有错误消息的已保存文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!