pjfanning opened a new pull request, #1420: URL: https://github.com/apache/poi/pull/1420
Fixes [bug 70146](https://bz.apache.org/bugzilla/show_bug.cgi?id=70146) and the remaining currency/accounting part of [bug 54686](https://bz.apache.org/bugzilla/show_bug.cgi?id=54686). ### Bug 70146: `[$USD]` without the language info The language info of a currency string is optional (`[$<Currency String>-<language info>]`), but `DataFormatter` only recognised the form with a `-`: | Format | Before | After | |---|---|---| | `#,##0.00\ [$USD];\-#,##0.00\ [$USD]` | `12,345.00 [$USD]` | `12,345.00 USD` | | `[$HKD $]#,##0` | `[$HKD $]12,345` | `HKD $12,345` | The symbol is now escaped character by character, so letters and dots in it (`EUR`, `Bs.`) are not read as pattern characters. Quoting it instead would make `"USD" 0` count as a date format, because `DateUtil.isADateFormat` keeps the date letters in quoted text. The old loop also replaced every currency string with the first one, and used the symbol as a regex replacement (hence the `\$` workaround). Both are fixed. The bug's attachment is added as `test-data/spreadsheet/bug70146.xlsx`. ### Bug 54686: a dot in literal text after the digits The reported formats, using a currency abbreviation that ends with a dot (`"тг."`, in the kk-KZ locale, which has a comma decimal separator): | Format | Before | After | |---|---|---| | `#,##0.000000000"тг."` | `0.001` (falls back to General) | `0.001000000тг.` | | `_-* #,##0.000000000"тг."_-;…` (accounting), kk-KZ | `0,001000000тг,` | `0,001000000тг.` | - `DataFormatter` stripped the quotes and passed the text to `DecimalFormat` unquoted. A second `.` made the pattern invalid. Literal characters that `DecimalFormat` treats as special (`0 # . , ; % ‰ E ¤`) are now quoted. This also stops a quoted `,` scaling the value, and a quoted `%` multiplying it. - `CellNumberFormatter`, which formats any format with 3 or more sections, replaced every `.` and `,` in the format with the locale's separators. It now localises only the decimal point. The grouping commas are already removed by then, so any other `.` or `,` is literal text. The fraction part of 54686 was fixed in 3.x; the fraction formats it reports all match Excel. Not changed: negative values in accounting formats are shown with extra spaces (`- 0.00`) by the `*` fill. That is the same on trunk without literal text. ### Tests - `TestDataFormatter`, `TestHSSFDataFormatter`, `TestDateUtil`, `TestHSSFDateUtil` and the `ss.format` tests pass. - In poi-ooxml, `TestDataFormatterAgainstExcel` (all 569 cases), `TestCellFormatPart`, `TestXSSFDataFormat`, `TestXSSFWithLocale` and the new `TestXSSFBugs.testBug70146` 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]
