apache / apache/poi

Wrong Data Format (String) corrupts formatted values

Open
#977 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
2.3k
Forks
844
Avg merge
5h 52m
Merged PRs (30d)
47

Description

Library version 5.5.1:

cell, having number cell style defined as
`#.##0,00 _€;[Red]-#.##0,00 _€ `
returns
`#,##0.00_);[Red](#,##0.00) `
on call to cell.getCellStyle().getDataFormatString - it corresponds to built-in style 40 (0x28)
negative values, formatted with this format by call to
`DataFormatter.formatRawCellContents`
return positive values in round brackets, so the value is effectively corrupted while using streaming event mode with XSSFSheetXMLHandler.

Here is the full code and sample file [poi_formatting_problem.xls](https://github.com/user-attachments/files/24216439/poi_formatting_problem.xls) to reproduce the issue
```

try (var wb = WorkbookFactory.create(new File("poi_formatting_problem.xls")))
{

//Style (as seen in Excel) #.##0,00 _€;[Red]-#.##0,00 _€
//is converted to #,##0.00_);[Red](#,##0.00)
var sheet = wb.getSheetAt(0);
var row = sheet.getRow(0);
var cell = row.getCell(0);
var str = new DataFormatter().formatRawCellContents(cell.getNumericCellValue(), cell.getCellStyle().getDataFormat(),

cell.getCellStyle().getDataFormatString());
//str is (378.13) instead of -378.13
}

```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with DataFormatter.formatRawCellContents and the style/data-format handling shown in the reproduction, using WorkbookFactory to inspect the supplied sample file. Compare the format returned by getCellStyle().getDataFormatString with the original Excel style and verify the negative value through the streaming XSSFSheetXMLHandler path; done means it remains negative rather than appearing in brackets.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.