Skip to content

Wrong Data Format (String) corrupts formatted values #977

Description

@chpasha

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 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
		}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions