Skip to content

fix(sheet): read the OOXML ISO date cell type instead of aborting - #1285

Merged
bengbengbalabalabeng merged 2 commits into
apache:mainfrom
Sean-Walker0:fix/xlsx-iso-date-cell
Nov 23, 2026
Merged

bengbengbalabalabeng merged 2 commits into
apache:mainfrom
Sean-Walker0:fix/xlsx-iso-date-cell

Conversation

@Sean-Walker0

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

Copy link
Copy Markdown
Contributor

Purpose of the pull request

The ST_CellType value d - an ISO-8601 date-string cell, supported since ECMA-376 2nd edition and, from the 4th edition on, retained only in the Strict schema (removed from Transitional) - was not known to the type routing map, so CellTagHandler threw Invalid cell data type: 'd' in cell A1 and aborted the entire read on the first such cell. A single such cell killed the whole file read.

Excel itself does not write t="d" (it writes date serials), but the type is part of the OOXML schema and third-party OOXML producers emit it; POI's own SAX reader (XSSFSheetXMLHandler) does not recognize d explicitly - the raw text only survives as a compatibility fallback when the numeric parse fails.

Reproduced on current main with a minimal spec-valid workbook (hand-crafted OPC package, one t="d" cell): the read throws; the same package with a plain number cell reads fine.

No issue exists for this yet; found while auditing the XLSX cell-type routing.

What's changed?

CellDataTypeEnum.TYPE_ROUTING_MAP routes "d" to DIRECT_STRING — the ISO-8601 text is kept as the cell value, matching how the other non-shared-string text forms (str, inlineStr) are handled. Genuinely unknown types still throw, preserving the intent of the unknown-type guard (#965).

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

IsoDateCellTypeTest:

  • isoDateCellReadsAsText — red before (ExcelAnalysisException: Invalid cell data type: 'd' in cell A1), green after: the crafted workbook reads and the cell yields the ISO text;

  • plainNumberCellStillReads — pins ordinary reads of the same package shape, green on both sides;

  • isoDateTypeRoutesToDirectString — unit-pins the routing ("d" -> DIRECT_STRING) and that unknown types still answer null, green on both sides of the second assertion and red on the first before the change.

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

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

Notes

@skytin1004 skytin1004 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.

Hi @Sean-Walker0, I tested this on Windows with Java 11. The product fix works, but the new integration test fails because File.separator creates an invalid classpath resource path. Could you please use / or the existing resource helper so the test also runs on Windows?

@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 @Sean-Walker0 — I reproduced skytin1004's Windows failure and verified the product fix independently (Windows 11, JDK 17).

Reproduction (PR head as-is)
IsoDateCellTypeTest fails 2/3 on Windows:

ExcelCommonException: Convert excel format exception...
Caused by: ExcelAnalysisException: File ...\target\test-classes\typed%5cnumber-cell.xlsx not exists.

The backslash from File.separator is URL-encoded to %5c in the classpath resource URL, so new File(url.getFile()) points at a non-existent file.

Verification

  • With resource() changed to "typed/" + name: IsoDateCellTypeTest 3/3 green.
  • With the routing change reverted (patched test left in place): Invalid cell data type: 'd' in cell A1 — the product fix is what makes the ISO cell readable.

Suggestion
AbstractExcelTest already provides readFile(String resourcePath), which normalizes / and File.separator segments and copies the resource into the per-test temp dir (robust when resources live in a JAR). Since the test already extends AbstractExcelTest, the custom resource() helper can be replaced with readFile("typed/" + name) — that fixes the Windows failure and the JAR case in one go.

Everything else looks good to me: routing "d" to DIRECT_STRING matches the str/inlineStr handling, and the unit test pins unknown types to null.

@Sean-Walker0
Sean-Walker0 force-pushed the fix/xlsx-iso-date-cell branch from c759d1b to e31f218 Compare November 8, 2026 06:25
@Sean-Walker0

Copy link
Copy Markdown
Contributor Author

Fixed — the test now loads the crafted workbooks through the existing readFile("typed/" + name) helper instead of building a File from the classpath URL, so the %5c encoding problem on Windows (and the JAR case) is gone. IsoDateCellTypeTest 3/3 green on Linux, spotless clean. The product change is untouched.

@Sean-Walker0
Sean-Walker0 force-pushed the fix/xlsx-iso-date-cell branch 4 times, most recently from 773298a to 3288168 Compare November 11, 2026 11:26
@bengbengbalabalabeng

Copy link
Copy Markdown
Contributor

Thanks for the contribution!

The implementation looks good to me. I only have a few documentation/comment wording suggestions for accuracy and clarity:

ECMA-376 section 18.18.11 defines the cell type t="d": a date cell whose value is an ISO-8601 string.

The ST_CellType value d has been supported since ECMA-376 2nd edition. However, strarting with the 4th edition, the d type was retained only in the Strict schema (Part 1) and removed from the Transitional schema (Part 4).

https://ecma-international.org/publications-and-standards/standards/ecma-376/

POI's own reader handles it as a first-class type.

I'm not sure "first-class type" is the most accurate description here.

Apache POI v5.x uses the ECMA-376 5th edition OOXML schemas (Transitional), in which the d cell type is not part of the schema. In the SAX reader path, XSSFSheetXMLHandler does not explicitly recognize d either; it falls through to the numeric branch and continues only because the parseDouble failure is caught and the raw string value is emitted. Because of that, I would consider this more of a compatibility fallback than explicit support for the d cell type.

https://github.com/apache/poi/blob/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/eventusermodel/XSSFSheetXMLHandler.java#L438-L450

@skytin1004 skytin1004 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.

Hi @Sean-Walker0, I re-reviewed the latest commit. The Windows resource-path issue is fixed by using the existing readFile("typed/" + name) helper, and the implementation and tests look good to me.

I agree with @bengbengbalabalabeng's accuracy notes: t="d" should be described as Strict-schema support or compatibility handling, rather than as a generally valid OOXML type or explicit POI support. Please update the PR description and the new source/test comments accordingly. This is documentation wording only, so I don't think it needs to block the implementation.

@Sean-Walker0

Copy link
Copy Markdown
Contributor Author

Thanks for the corrections — both wording issues are fixed:

  1. The description and the enum comment now state the actual history: ST_CellType value d is supported since ECMA-376 2nd edition, and from the 4th edition on it only remains in the Strict schema (removed from Transitional), instead of citing the section number alone.
  2. The POI claim is reworded: their SAX reader (XSSFSheetXMLHandler) does not recognize d explicitly — the raw text only survives as a compatibility fallback when the numeric parse fails — rather than "first-class type" support.

No code behavior change (the comment text update is folded into the existing commit).

@Sean-Walker0
Sean-Walker0 force-pushed the fix/xlsx-iso-date-cell branch from 3288168 to cec76cb Compare November 23, 2026 07:34
ECMA-376 section 18.18.11 defines the cell type t="d": a date cell
holding an ISO-8601 string. The type routing map did not know it, so
CellTagHandler threw 'Invalid cell data type: d' and aborted the
entire read on the first such cell - a spec-valid file that POI itself
reads. Excel does not write t="d", but third-party OOXML producers do.

Route "d" to DIRECT_STRING, keeping the ISO-8601 text as the cell
value like the other non-shared-string text forms. Genuinely unknown
types still throw, preserving the intent of the unknown-type guard.

Verified with IsoDateCellTypeTest (a crafted spec-valid workbook with
a t="d" cell aborts the read before the change and reads the ISO
text after; a plain-number workbook and the unknown-type rejection
are pinned on both sides) plus the full fesod-sheet suite (1792
tests) and spotless:check.
@Sean-Walker0
Sean-Walker0 force-pushed the fix/xlsx-iso-date-cell branch from cec76cb to 13c0f8a Compare November 23, 2026 07:37

@bengbengbalabalabeng bengbengbalabalabeng 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.

LGTM.

@bengbengbalabalabeng
bengbengbalabalabeng merged commit f8549a4 into apache:main Nov 23, 2026
14 checks passed
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.

4 participants