Skip to content

fix(sheet): match sheet names case-insensitively when reading - #1286

Open
Sean-Walker0 wants to merge 1 commit into
apache:mainfrom
Sean-Walker0:fix/read-sheet-name-case-insensitive
Open

Sean-Walker0 wants to merge 1 commit into
apache:mainfrom
Sean-Walker0:fix/read-sheet-name-case-insensitive

Conversation

@Sean-Walker0

@Sean-Walker0 Sean-Walker0 commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Purpose of the pull request

SheetUtils.match compared the requested sheet name with the workbook's tab name case-sensitively, while the workbook model itself resolves sheet names case-insensitively — POI's Workbook.getSheet(String) (which fesod's write and fill paths go through) matches data/Data/DATA against a Data tab. The same request on the two paths therefore behaved differently:

tab "Data"
write:  FesodSheet.write(...).withTemplate(t).sheet("DATA")...  -> fills the tab (POI, case-insensitive)
read:   FesodSheet.read(f).sheet("DATA")...                     -> zero rows, silently

A case-differing read name delivers an empty result with no error, which is easy to hit (constants vs tab names) and hard to notice.

Reproduced on current main: .sheet("data") and .sheet("DATA") on a Data tab read 0 rows; POI's getSheet finds the tab for both.

No issue exists for this yet; found while probing read/write name-matching symmetry.

What's changed?

The name comparison in SheetUtils.match ignores case. The surrounding strip/trim handling (autoStrip/autoTrim preprocessing of both names) is unchanged, and exact names keep matching as before. Sheet-number matching is untouched.

Checklist

  • I have read the Contributor Guide.
  • I have written the necessary doc or comment.
  • I have added the necessary unit tests and all cases have passed.

Verifying this change

SheetNameCaseInsensitiveReadTest (one workbook, tab Data):

  • red before (a lowercase variant matches like POI's getSheet ==> expected: <1> but was: <0>);

  • green after: Data, data and DATA each read the row, while an unrelated name still reads 0 rows.

  • Existing SheetUtilsTest: 7/7 (including the autoStrip name-matching cases).

  • ./mvnw clean package -B -Dmaven.test.skip=false -pl fesod-common,fesod-shaded,fesod-sheet: 1790 tests, 0 failures, 0 errors.

  • ./mvnw -pl fesod-sheet spotless:check: clean.

Notes

  • Behavior change: reads that previously silently returned no rows because of a case difference now match the tab. Excel enforces case-insensitive uniqueness of sheet names (and POI rejects a case-duplicate createSheet), so two tabs differing only in case cannot come from a real workbook - the matching can never be ambiguous for well-formed files; a hand-crafted package is the only way to reach such a pair, where first-match applies like POI getSheet
  • The comparison exists in the same form in the EasyExcel lineage; the fix aligns the read path with the POI semantics the write path already relies on.
  • Orthogonal to open PRs: no open PR touches SheetUtils.

@Mikkey-f Mikkey-f left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks — I verified this on Windows/JDK 17.

Verification

  • SheetNameCaseInsensitiveReadTest passes on the PR head; reverting equalsIgnoreCase to equals makes the data/DATA assertions fail with expected: <1> but was: <0>, so the test pins the fix.
  • SheetUtilsTest still passes (7/7), so exact-name and autoStrip/autoTrim paths are unaffected.

One factual correction: the Notes say tabs differing only in case are legal in Excel, but sheet names are case-insensitively unique there — POI validates it too: createSheet("DATA") after createSheet("Data") throws The workbook already contains a sheet named 'DATA'. So that ambiguity is only reachable with a hand-crafted package; worth adjusting the note.

Non-blocking suggestions

  • The test covers XLSX only; SheetUtils.match is shared by the XLS and CSV executors, so an XLS case through the existing format parameterization would guard the same path.
  • Minor style: the test uses the fully-qualified org.apache.fesod.sheet.testkit.enums.ExcelFormat.XLSX inline.

No blocking issues from my side.

@Sean-Walker0
Sean-Walker0 force-pushed the fix/read-sheet-name-case-insensitive branch 2 times, most recently from 125e101 to ee4d45c Compare November 8, 2026 06:42
@Sean-Walker0

Copy link
Copy Markdown
Contributor Author

Thanks for the verification and the correction — all three points addressed and force-pushed as ee4d45c:

  1. The Notes now state that Excel enforces case-insensitive sheet-name uniqueness (POI rejects case-duplicate createSheet), so the ambiguity note only concerns hand-crafted packages.
  2. Added readBySheetNameMatchesCaseInsensitivelyOnXls: an HSSF workbook going through the same SheetUtils.match path (the test now builds the file per ExcelFormat).
  3. The test imports ExcelFormat instead of the FQCN.

SheetNameCaseInsensitiveReadTest 2/2 + SheetUtilsTest 7/7 green, spotless clean.

@Sean-Walker0
Sean-Walker0 force-pushed the fix/read-sheet-name-case-insensitive branch 3 times, most recently from 05d7277 to 5362b0f Compare November 11, 2026 11:28
SheetUtils.match compared the requested sheet name with the workbook's
tab name case-sensitively, while the workbook model itself resolves
sheet names case-insensitively: POI's Workbook.getSheet (which the
write and fill paths use) matches 'data', 'Data' and 'DATA' against a
'Data' tab. Reading the same workbook with the same name variants
silently delivered zero rows with no error - the read/write pair
behaved differently for the identical request.

Compare names ignoring case. The strip/trim handling above the
comparison is unchanged, and exact names keep matching as before.

Verified with SheetNameCaseInsensitiveReadTest (the lowercase variant
reads 0 rows before the change and 1 after; the exact-name and
unrelated-name cases are pinned on both sides) plus the existing
SheetUtilsTest, the full fesod-sheet suite (1790 tests) and
spotless:check.
@Sean-Walker0
Sean-Walker0 force-pushed the fix/read-sheet-name-case-insensitive branch from 5362b0f to 20fecf8 Compare November 23, 2026 07:39

This branch has not been deployed

No deployments
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