2
votes

I'm using openpyxl to import/export xlsx files.

But I can't import load_workbook() the file that i exported with openpyxl.

I must open the exported xlsx file in Excel, change some value of the imported xlsx file and save it (its size changes also (for ex: from 148 Ko to 180 Ko). Then i can import it with openpyxl.

I think that there is a problem in export because after saving manually import works.

Thanks.

1
It is unclear where you import and export from. Are you using an external program that does use import and export or are you just using that terminology instead of load_workbook() and Workbook.save(). If you provide some code, that would be helpful preferably with something that creates the file that cannot be 'imported'. Did you try to read the faulty file with Excel?Anthon

1 Answers

1
votes

It seems this doesn't currently work: https://bitbucket.org/ericgazoni/openpyxl/issue/46/problem-reading-one-excel-file-and-writing

import openpyxl
wb = openpyxl.Workbook()
ws = wb.get_active_sheet()
ws.cell('A1').value = 1
wb.save('test.xslx')
wb2 = openpyxl.load_workbook('test.xlsx')
ws2 = wb2.get_active_sheet()
ws2.cell('A2').value = 2
wb2.save('test2.xlsx')