openpyxl - load the workbook and save , open saved file with error message

匆匆过客 提交于 2019-12-06 09:46:04

问题


Error Message while opening the file:

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.

If I say "Yes" got "Repairs to zz.xlxs" pop up shows.

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.

My code :

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!


回答1:


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.

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)



回答2:


You can try and validate the file created with the MS Office OpenXML Productivity Tool but only if it was created on a machine with lxml installed. Otherwise please submit a bug with the script you actually used to create a file.



来源:https://stackoverflow.com/questions/29355778/openpyxl-load-the-workbook-and-save-open-saved-file-with-error-message

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!