]> source.dussan.org Git - poi.git/commitdiff
Fix bug #50756 - When formatting numbers based on their Cell Style, treat GENERAL...
authorNick Burch <nick@apache.org>
Fri, 11 Feb 2011 12:31:40 +0000 (12:31 +0000)
committerNick Burch <nick@apache.org>
Fri, 11 Feb 2011 12:31:40 +0000 (12:31 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1069775 13f79535-47bb-0310-9956-ffa450edef68

src/documentation/content/xdocs/status.xml
src/java/org/apache/poi/ss/usermodel/DataFormatter.java
src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java
test-data/spreadsheet/50756.xls [new file with mode: 0644]

index 6bcbea14e86581a4a037594b388cb18b1015b7c9..9d8639c9c019eeaceca64ca1a1dd879235846c2f 100644 (file)
@@ -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>
index de586db66abe2c69e99df6816ecc749dc62c8017..38afc61d345611077f48a6b183924efe1f42b61f 100644 (file)
@@ -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;
             }
index 09ff05c0cbd29ff4e1abeaa275386ee6def17f61..440f3a3953c6791b5f59c80bfffb52fa986399c1 100644 (file)
@@ -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)));
+    }
 }
diff --git a/test-data/spreadsheet/50756.xls b/test-data/spreadsheet/50756.xls
new file mode 100644 (file)
index 0000000..f7e595d
Binary files /dev/null and b/test-data/spreadsheet/50756.xls differ