Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

excel

openpyxl

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!

like image 986
Monty Avatar asked Mar 30 '15 20:03

Monty


1 Answers

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)
like image 79
castledom04 Avatar answered Oct 06 '22 19:10

castledom04