Skip to content

feat: add getFirstWorksheet() method to safely get first existing worksheet #2991

Open
freepad wants to merge 3 commits intoexceljs:masterfrom
freepad:feature/getFirstWorksheet
Open

feat: add getFirstWorksheet() method to safely get first existing worksheet #2991
freepad wants to merge 3 commits intoexceljs:masterfrom
freepad:feature/getFirstWorksheet

Conversation

@freepad
Copy link
Copy Markdown

@freepad freepad commented Nov 3, 2025

Summary

This method finds and returns the first worksheet that exists (not deleted), regardless of its id. Resolves the issue where getWorksheet(1) would fail after deleting the first worksheet.

Problem: When users delete worksheets, the IDs don't get reassigned. So after deleting worksheet with id=1, calling getWorksheet(1) returns undefined even though other worksheets exist.

Solution: The new getFirstWorksheet() method finds the first existing worksheet in the internal array, providing a reliable way to get the first worksheet regardless of deletions.

Test plan

I wrote unit-tests covering all scenarios:

  • Returns first worksheet normally
  • Returns correct worksheet after single/multiple deletions
  • Returns undefined when no worksheets exist

Run with:

npm run test:unit -- spec/unit/doc/workbook.spec.js --grep "getFirstWorksheet"

All tests pass (5/5).

…ksheet

This method finds and returns the first worksheet that exists (not deleted), regardless of its id. Resolves the issue where getWorksheet(1) would fail after deleting the first worksheet.
…ksheet

This method finds and returns the first worksheet that visible.
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.

1 participant