pjfanning opened a new pull request, #1424: URL: https://github.com/apache/poi/pull/1424
Fixes [bug 61638](https://bz.apache.org/bugzilla/show_bug.cgi?id=61638). `DecimalFormat` doesn't accept a `0` placeholder followed by `#` or `?` placeholders, so `DataFormatter` fell back to General for formats like these. They are now formatted by `CellFormat`, as `DataFormatter` already does for literal text between digits. | Format | Value | Before | After = Excel | |---|---|---|---| | `60#########` | 166609647 | `166609647` | `60166609647` | | `60#########` | 12345678 | `12345678` | `6012345678` | | `0##` (comment 4) | 5 | `5` | `05` | The expected values were checked in Excel for the web with `=TEXT(12345678,"60#########")`, `=TEXT(5,"0##")` and `=TEXT(166609647,"60#########")`. They confirm comment 3: Excel shows the `0` only in its own position. It does not fill the `#` positions after it with zeros, as Java's `'60'000000000` would. `CellFormat` creates a format for some patterns it can't actually apply, e.g. the deliberately malformed `#''0#0'1#10L16EE` in `TestHSSFDataFormatter` (an NPE in `apply`). So the `CellFormat` is now applied once while the format is being created, inside the existing try/catch, and such patterns fall back to General as before. This covers the existing literal-between-digits route too. Tests: `TestDataFormatter` (new `testZeroBeforeOptionalDigits`), `TestHSSFDataFormatter` and the `ss.format` tests pass. In poi-ooxml, `TestDataFormatterAgainstExcel` (569 cases) and `TestXSSFDataFormat` pass. 🤖 Generated with [Claude Code](https://claude.com/claude-code) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
