aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorNick Burch <nick@apache.org>2011-02-11 12:31:40 +0000
committerNick Burch <nick@apache.org>2011-02-11 12:31:40 +0000
commit39287621938f695c45ec48b5213994203747d0ed (patch)
tree3a4f474ef69dc826a44784ee639260dbb4b0d89b /src
parent20062200df5d7684a67674ecf6783275b4dcdc6a (diff)
downloadpoi-39287621938f695c45ec48b5213994203747d0ed.tar.gz
poi-39287621938f695c45ec48b5213994203747d0ed.zip
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
Diffstat (limited to 'src')
-rw-r--r--src/documentation/content/xdocs/status.xml1
-rw-r--r--src/java/org/apache/poi/ss/usermodel/DataFormatter.java2
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java33
3 files changed, 35 insertions, 1 deletions
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 @@
<changes>
<release version="3.8-beta1" date="2010-??-??">
+ <action dev="poi-developers" type="fix">50756 - When formatting numbers based on their Cell Style, treat GENERAL the same as the more typical General</action>
<action dev="poi-developers" type="fix">fixed HSSFWorkbook.createCellStyle to throw exception if the maximum number of cell styles was exceeded</action>
<action dev="poi-developers" type="fix">50539 - Better fix for html-style br tags (invalid XML) inside XSSF documents</action>
<action dev="poi-developers" type="add">49928 - allow overridden built-in formats in HSSFCellStyle</action>
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)));
+ }
}