jsonkenl / xlsxir

Xlsx parser for the Elixir language.
MIT License
212 stars 83 forks source link

Fix swapped sheets misnaming #122

Open marcpeabody opened 11 months ago

marcpeabody commented 11 months ago

The names of worksheets are saved to an ets table while parsing the workbook. The workbook parser presently uses the sheetId attribute of the sheet tag to match up the worksheet name attribute with its 1-based index position of the corresponding worksheet.

Unfortunately, the sheetId is an unreliable source because it works like a generated primary key on a relational database. This means: 1) If a sheet ever gets deleted, a gap is left in the sheetId number sequence (1,2,4,5) 2) If a sheet is ever placed out of order, the sheetId number sequence becomes out of order (1,5,3,2,4)

This can result in the worksheet names not reporting correctly from this framework.

However, the order of the sheet tags in the workbook XML are in the order of the actual given worksheets. This PR relies on the order of the sheet tags in the workbook XML. A test has been added to verify this behavior using an xlsx file created in Excel. Other xlsx files created in Google Sheets and Apple Numbers were also used for manual testing to verify this behavior.