Skip to content

Add a patch to handle badly formed XLS files#281

Merged
zdavatz merged 1 commit into
zdavatz:masterfrom
botsandus:elliotcm/xls-fix
Apr 21, 2026
Merged

Add a patch to handle badly formed XLS files#281
zdavatz merged 1 commit into
zdavatz:masterfrom
botsandus:elliotcm/xls-fix

Conversation

@elliotcm
Copy link
Copy Markdown
Contributor

@elliotcm elliotcm commented Apr 21, 2026

This pull request addresses an edge case in reading Excel XLS files where some writers emit ROW records with empty cell ranges, which previously led to incorrect row data being returned. The fix ensures that valid cell data is preserved even when such ROW records are encountered. The most important changes are grouped below:

Bug Fix for Reading Rows with Empty Cell Ranges:

  • Updated set_row_address in lib/spreadsheet/excel/reader.rb to preserve the original row offset and block when a ROW record has first_used == first_unused but cell data exists, preventing incorrect seeking and empty row results.

Internal API changes:

  • Exposed the row_addresses attribute in Spreadsheet::Excel::Worksheet to allow tracking and referencing row offsets during parsing.

Test Coverage:

  • Added a new integration test test_row_record_with_empty_cell_range in test/integration.rb to verify that rows with cell data are correctly read even when the ROW record claims no cells.

The sample file is generated from scratch in order to be anonymous, but it has been tested against a full original file that exhibits the issue.

@zdavatz zdavatz merged commit 623bcb9 into zdavatz:master Apr 21, 2026
9 checks passed
@zdavatz
Copy link
Copy Markdown
Owner

zdavatz commented Apr 21, 2026

Thank you for the PR! Will do a new release now!

@elliotcm elliotcm deleted the elliotcm/xls-fix branch April 21, 2026 14:38
zdavatz added a commit that referenced this pull request Apr 21, 2026
Includes PR #281 (handle badly formed XLS files).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@zdavatz
Copy link
Copy Markdown
Owner

zdavatz commented Apr 21, 2026

Successfully registered gem: spreadsheet (1.3.5)

@elliotcm
Copy link
Copy Markdown
Contributor Author

@zdavatz Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants