From 39287621938f695c45ec48b5213994203747d0ed Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Fri, 11 Feb 2011 12:31:40 +0000 Subject: Fix bug #50756 - When formatting numbers based on their Cell Style, treat GENERAL the same as the more typical General git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1069775 13f79535-47bb-0310-9956-ffa450edef68 --- src/documentation/content/xdocs/status.xml | 1 + .../org/apache/poi/ss/usermodel/DataFormatter.java | 2 +- .../org/apache/poi/hssf/usermodel/TestBugs.java | 33 ++++++++++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index 6bcbea14e8..9d8639c9c0 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -34,6 +34,7 @@ + 50756 - When formatting numbers based on their Cell Style, treat GENERAL the same as the more typical General fixed HSSFWorkbook.createCellStyle to throw exception if the maximum number of cell styles was exceeded 50539 - Better fix for html-style br tags (invalid XML) inside XSSF documents 49928 - allow overridden built-in formats in HSSFCellStyle diff --git a/src/java/org/apache/poi/ss/usermodel/DataFormatter.java b/src/java/org/apache/poi/ss/usermodel/DataFormatter.java index de586db66a..38afc61d34 100644 --- a/src/java/org/apache/poi/ss/usermodel/DataFormatter.java +++ b/src/java/org/apache/poi/ss/usermodel/DataFormatter.java @@ -196,7 +196,7 @@ public class DataFormatter { if (format != null) { return format; } - if ("General".equals(formatStr) || "@".equals(formatStr)) { + if ("General".equalsIgnoreCase(formatStr) || "@".equals(formatStr)) { if (DataFormatter.isWholeNumber(cellValue)) { return generalWholeNumFormat; } diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java b/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java index 09ff05c0cb..440f3a3953 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java @@ -43,6 +43,7 @@ import org.apache.poi.ss.formula.ptg.Ptg; import org.apache.poi.ss.usermodel.BaseTestBugzillaIssues; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.CellStyle; +import org.apache.poi.ss.usermodel.DataFormatter; import org.apache.poi.ss.usermodel.Name; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; @@ -1953,4 +1954,36 @@ if(1==2) { assertEquals("Cell A,1", sheet.getRow(1).getCell(0).getStringCellValue()); assertEquals("Cell A,3", sheet.getRow(2).getCell(0).getStringCellValue()); } + + /** + * If you send a file between Excel and OpenOffice enough, something + * will turn the "General" format into "GENERAL" + */ + public void test50756() throws Exception { + HSSFWorkbook wb = openSample("50756.xls"); + HSSFSheet s = wb.getSheetAt(0); + HSSFRow r17 = s.getRow(16); + HSSFRow r18 = s.getRow(17); + HSSFDataFormatter df = new HSSFDataFormatter(); + + assertEquals(10.0, r17.getCell(1).getNumericCellValue()); + assertEquals(20.0, r17.getCell(2).getNumericCellValue()); + assertEquals(20.0, r17.getCell(3).getNumericCellValue()); + assertEquals("GENERAL", r17.getCell(1).getCellStyle().getDataFormatString()); + assertEquals("GENERAL", r17.getCell(2).getCellStyle().getDataFormatString()); + assertEquals("GENERAL", r17.getCell(3).getCellStyle().getDataFormatString()); + assertEquals("10", df.formatCellValue(r17.getCell(1))); + assertEquals("20", df.formatCellValue(r17.getCell(2))); + assertEquals("20", df.formatCellValue(r17.getCell(3))); + + assertEquals(16.0, r18.getCell(1).getNumericCellValue()); + assertEquals(35.0, r18.getCell(2).getNumericCellValue()); + assertEquals(123.0, r18.getCell(3).getNumericCellValue()); + assertEquals("GENERAL", r18.getCell(1).getCellStyle().getDataFormatString()); + assertEquals("GENERAL", r18.getCell(2).getCellStyle().getDataFormatString()); + assertEquals("GENERAL", r18.getCell(3).getCellStyle().getDataFormatString()); + assertEquals("16", df.formatCellValue(r18.getCell(1))); + assertEquals("35", df.formatCellValue(r18.getCell(2))); + assertEquals("123", df.formatCellValue(r18.getCell(3))); + } } -- cgit v1.2.3