pjfanning opened a new pull request, #1425:
URL: https://github.com/apache/poi/pull/1425

   Relates to #977.
   
   Excel does not store the format string of most built-in formats in a 
workbook, just the index, and it shows some of them differently depending on 
the locale of the Excel installation. For example, German Excel shows index 40 
as `#,##0.00 _€;[Red]-#,##0.00 _€`, while POI always uses the en-US 
`#,##0.00_);[Red](#,##0.00)`, so negative numbers come out in brackets. An 
.xlsx file has no locale information, so POI cannot work this out itself.
   
   This adds `DataFormatter.setBuiltinFormatOverride(int, String)` (plus a 
getter), so callers can supply the format string for the workbook's locale:
   
   ```java
   DataFormatter formatter = new DataFormatter();
   formatter.setBuiltinFormatOverride(40, "#,##0.00 _€;[Red]-#,##0.00 _€");
   ```
   
   - The override applies in `formatCellValue`, `createFormat(Cell)` and 
`formatRawCellContents`. The streaming handlers (`XSSFSheetXMLHandler`, 
`XSSFBSheetHandler`, `FormatTrackingHSSFListener`) and the extractors all use 
`formatRawCellContents`, so they pick it up through the `DataFormatter` passed 
to them.
   - The override is used only when the cell's format string is the default one 
for that index. A format string that the workbook stores explicitly for a 
built-in index (e.g. Excel writes the locale's currency formats for 5-8 and 
41-44) is still used as is.
   - Throws `IllegalArgumentException` for an index that isn't a built-in 
format.
   
   🤖 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]

Reply via email to