diff --git a/src/documentation/content/xdocs/changes.xml b/src/documentation/content/xdocs/changes.xml index a279c64ac..cdb6bdfe8 100644 --- a/src/documentation/content/xdocs/changes.xml +++ b/src/documentation/content/xdocs/changes.xml @@ -37,6 +37,7 @@ + 47154 - Handle the cell format @ as the same as General 47048 - Fixed evaluation of defined names with the 'complex' flag set 46953 - More tweaks to PageSettingsBlock parsing logic in Sheet constructor 47089 - Fixed XSSFWorkbook.createSheet to properly increment sheetId diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index 65e7caa03..2008d00b3 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -34,6 +34,7 @@ + 47154 - Handle the cell format @ as the same as General 47048 - Fixed evaluation of defined names with the 'complex' flag set 46953 - More tweaks to PageSettingsBlock parsing logic in Sheet constructor 47089 - Fixed XSSFWorkbook.createSheet to properly increment sheetId diff --git a/src/java/org/apache/poi/ss/usermodel/DataFormatter.java b/src/java/org/apache/poi/ss/usermodel/DataFormatter.java index 378f3303c..50e3690f7 100755 --- a/src/java/org/apache/poi/ss/usermodel/DataFormatter.java +++ b/src/java/org/apache/poi/ss/usermodel/DataFormatter.java @@ -147,7 +147,7 @@ public class DataFormatter { if (format != null) { return format; } - if (formatStr.equals("General")) { + if (formatStr.equals("General") || formatStr.equals("@")) { if (DataFormatter.isWholeNumber(cellValue)) { return generalWholeNumFormat; } 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 index 000000000..2840cc61b Binary files /dev/null and b/src/testcases/org/apache/poi/hssf/data/47154.xls differ diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDataFormatter.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDataFormatter.java index e1a6e1b3c..718d909b6 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDataFormatter.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDataFormatter.java @@ -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