append method breaks final xlsx file
Issue #1345
resolved
from openpyxl import load_workbook import os basedir = '/home/user/projects/test_openpyxl' template = os.path.join(basedir, 'test.xlsx') wb_t = load_workbook(template) wall_sheet = wb_t[u'2.1'] r = [1, 2, 3, 4, 5] wall_sheet.append(r) wb_t.save(os.path.join(basedir, 'testfileafterrun.xlsx'))
When updating from version 2.5.12 to 3.0.0 the code above started to break the final Excel file.
In
worksheet.py
Worksheet.append()
the last row of sheet is identified as 1048577, however indicated sheet has only 5 rows.
Comments (5)
-
-
reporter Do you mean that after opening initial file, appending to the sheet ‘2.1’ a list of digits and saving as a new file, the latest file is opened via MS Office or LibreOffice correctly and the digits, supposed to be inserted to the sheet ‘2.1’, are in place of row 6 ?
-
Not sure I really understand but you can simply set `
s._current_row=5`
-
reporter Yep, it shall probably help. However the bug is how it (
s._current_row
) is identified. -
- changed status to resolved
Set the current row of the worksheet to the highest cell in it. Resolves
#1345→ <<cset d7bdf443b356>>
- Log in to comment
Well, unfortunately the file contains rows up to the maximum. `<x:row r="1048576" customFormat="false" ht="12.8" hidden="false" customHeight="true" outlineLevel="0" collapsed="false" />`
But I can’t reproduce the error here.