]> source.dussan.org Git - poi.git/commitdiff
Fix bug #47154 - Handle the cell format @ as the same as General
authorNick Burch <nick@apache.org>
Sat, 16 May 2009 17:39:31 +0000 (17:39 +0000)
committerNick Burch <nick@apache.org>
Sat, 16 May 2009 17:39:31 +0000 (17:39 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@775500 13f79535-47bb-0310-9956-ffa450edef68

src/documentation/content/xdocs/changes.xml
src/documentation/content/xdocs/status.xml
src/java/org/apache/poi/ss/usermodel/DataFormatter.java
src/testcases/org/apache/poi/hssf/data/47154.xls [new file with mode: 0644]
src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDataFormatter.java

index a279c64ac2479a4c656401283148766b3caf0704..cdb6bdfe85ed667a94db749684d78a817800ad5e 100644 (file)
@@ -37,6 +37,7 @@
 
                <!-- Don't forget to update status.xml too! -->
         <release version="3.5-beta6" date="2009-??-??">
+           <action dev="POI-DEVELOPERS" type="fix">47154 - Handle the cell format @ as the same as General</action>
            <action dev="POI-DEVELOPERS" type="fix">47048 - Fixed evaluation of defined names with the 'complex' flag set</action>
            <action dev="POI-DEVELOPERS" type="fix">46953 - More tweaks to PageSettingsBlock parsing logic in Sheet constructor</action>
            <action dev="POI-DEVELOPERS" type="fix">47089 - Fixed XSSFWorkbook.createSheet to properly increment sheetId</action>
index 65e7caa030502d4a23bc34e9e5ff0ee45ef37485..2008d00b36bd21b0b9a923d1da9958a4bbc04b6b 100644 (file)
@@ -34,6 +34,7 @@
        <!-- Don't forget to update changes.xml too! -->
     <changes>
         <release version="3.5-beta6" date="2009-??-??">
+           <action dev="POI-DEVELOPERS" type="fix">47154 - Handle the cell format @ as the same as General</action>
            <action dev="POI-DEVELOPERS" type="fix">47048 - Fixed evaluation of defined names with the 'complex' flag set</action>
            <action dev="POI-DEVELOPERS" type="fix">46953 - More tweaks to PageSettingsBlock parsing logic in Sheet constructor</action>
            <action dev="POI-DEVELOPERS" type="fix">47089 - Fixed XSSFWorkbook.createSheet to properly increment sheetId</action>
index 378f3303ca32f7216ddf680616235d5a75a00408..50e3690f7c8cf4de1bc5d9107e67e49a27dbbfb3 100755 (executable)
@@ -147,7 +147,7 @@ public class DataFormatter {
         if (format != null) {\r
             return format;\r
         }\r
-        if (formatStr.equals("General")) {\r
+        if (formatStr.equals("General") || formatStr.equals("@")) {\r
             if (DataFormatter.isWholeNumber(cellValue)) {\r
                 return generalWholeNumFormat;\r
             }\r
diff --git a/src/testcases/org/apache/poi/hssf/data/47154.xls b/src/testcases/org/apache/poi/hssf/data/47154.xls
new file mode 100644 (file)
index 0000000..2840cc6
Binary files /dev/null and b/src/testcases/org/apache/poi/hssf/data/47154.xls differ
index e1a6e1b3caf09242cac2fba2549fa09da7d5d377..718d909b66bd5b1b76ec856a1d7b7b5faeec6f7a 100644 (file)
@@ -21,6 +21,8 @@ import java.text.DecimalFormat;
 import java.text.Format;
 import java.util.Iterator;
 
+import org.apache.poi.hssf.HSSFTestDataSamples;
+
 import junit.framework.TestCase;
 
 /**
@@ -267,6 +269,24 @@ public final class TestHSSFDataFormatter extends TestCase {
                        assertTrue(formatter.formatCellValue(cell).endsWith(" USD"));
                }
        }
+       
+       /**
+        * A format of "@" means use the general format
+        */
+       public void testGeneralAtFormat() {
+        HSSFWorkbook workbook = HSSFTestDataSamples.openSampleWorkbook("47154.xls");
+        HSSFSheet sheet       = workbook.getSheetAt(0);
+        HSSFRow   row         = sheet.getRow(0);
+        HSSFCell  cellA1      = row.getCell(0);
+        
+        assertEquals(HSSFCell.CELL_TYPE_NUMERIC, cellA1.getCellType());
+        assertEquals(2345.0, cellA1.getNumericCellValue(), 0.0001);
+        assertEquals("@", cellA1.getCellStyle().getDataFormatString());
+
+        HSSFDataFormatter f = new HSSFDataFormatter();
+        
+        assertEquals("2345", f.formatCellValue(cellA1));
+       }
 
        private static void log(String msg) {
                if (false) { // successful tests should be silent