diff options
author | Dominik Stadler <centic@apache.org> | 2013-10-16 19:47:21 +0000 |
---|---|---|
committer | Dominik Stadler <centic@apache.org> | 2013-10-16 19:47:21 +0000 |
commit | 34209b86617ed4d5fb6d30f83ca8f327938cb367 (patch) | |
tree | 20e1489470206c7daafe368da7e393ceb0236039 | |
parent | 5bc1aa8038fc498b5bb702b3ae11640f8577a41b (diff) | |
download | poi-34209b86617ed4d5fb6d30f83ca8f327938cb367.tar.gz poi-34209b86617ed4d5fb6d30f83ca8f327938cb367.zip |
Bug 55658: don't fail in SXSSF if a numeric cell is overwritten with a string
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1532873 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFCell.java | 23 | ||||
-rw-r--r-- | src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFCell.java | 34 |
2 files changed, 50 insertions, 7 deletions
diff --git a/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFCell.java b/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFCell.java index 46ca95fcf7..125dfac254 100644 --- a/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFCell.java +++ b/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFCell.java @@ -22,9 +22,17 @@ import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; -import org.apache.poi.ss.formula.eval.ErrorEval; -import org.apache.poi.ss.usermodel.*; import org.apache.poi.ss.formula.FormulaParseException; +import org.apache.poi.ss.formula.eval.ErrorEval; +import org.apache.poi.ss.usermodel.Cell; +import org.apache.poi.ss.usermodel.CellStyle; +import org.apache.poi.ss.usermodel.Comment; +import org.apache.poi.ss.usermodel.DateUtil; +import org.apache.poi.ss.usermodel.FormulaError; +import org.apache.poi.ss.usermodel.Hyperlink; +import org.apache.poi.ss.usermodel.RichTextString; +import org.apache.poi.ss.usermodel.Row; +import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.util.CellRangeAddress; import org.apache.poi.ss.util.CellReference; import org.apache.poi.xssf.usermodel.XSSFHyperlink; @@ -611,6 +619,7 @@ public class SXSSFCell implements Cell * Errors are displayed as #ERR<errIdx> * </p> */ + @Override public String toString() { switch (getCellType()) { case CELL_TYPE_BLANK: @@ -887,6 +896,7 @@ public class SXSSFCell implements Cell case CELL_TYPE_STRING: return getStringCellValue(); case CELL_TYPE_NUMERIC: + return Double.toString( getNumericCellValue() ); case CELL_TYPE_ERROR: byte errVal = getErrorCellValue(); return FormulaError.forInt(errVal).getString(); @@ -925,6 +935,7 @@ public class SXSSFCell implements Cell { super(value); } + @Override public int getType() { return COMMENT; @@ -936,6 +947,7 @@ public class SXSSFCell implements Cell { super(value); } + @Override public int getType() { return HYPERLINK; @@ -981,6 +993,7 @@ public class SXSSFCell implements Cell { return _value; } + @Override boolean isRichText() { return false; @@ -989,6 +1002,7 @@ public class SXSSFCell implements Cell static class RichTextValue extends StringValue { RichTextString _value; + @Override public int getType() { return CELL_TYPE_STRING; @@ -1001,6 +1015,7 @@ public class SXSSFCell implements Cell { return _value; } + @Override boolean isRichText() { return true; @@ -1026,6 +1041,7 @@ public class SXSSFCell implements Cell static class NumericFormulaValue extends FormulaValue { double _preEvaluatedValue; + @Override int getFormulaType() { return CELL_TYPE_NUMERIC; @@ -1042,6 +1058,7 @@ public class SXSSFCell implements Cell static class StringFormulaValue extends FormulaValue { String _preEvaluatedValue; + @Override int getFormulaType() { return CELL_TYPE_STRING; @@ -1058,6 +1075,7 @@ public class SXSSFCell implements Cell static class BooleanFormulaValue extends FormulaValue { boolean _preEvaluatedValue; + @Override int getFormulaType() { return CELL_TYPE_BOOLEAN; @@ -1074,6 +1092,7 @@ public class SXSSFCell implements Cell static class ErrorFormulaValue extends FormulaValue { byte _preEvaluatedValue; + @Override int getFormulaType() { return CELL_TYPE_ERROR; diff --git a/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFCell.java b/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFCell.java index fb45b73bf0..a73e952c8f 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFCell.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFCell.java @@ -19,7 +19,15 @@ package org.apache.poi.xssf.streaming; -import org.apache.poi.ss.usermodel.*; +import java.io.IOException; + +import javax.xml.namespace.QName; + +import org.apache.poi.ss.usermodel.BaseTestCell; +import org.apache.poi.ss.usermodel.Cell; +import org.apache.poi.ss.usermodel.Row; +import org.apache.poi.ss.usermodel.Sheet; +import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.xssf.SXSSFITestDataProvider; import org.apache.poi.xssf.XSSFITestDataProvider; import org.apache.poi.xssf.usermodel.XSSFCell; @@ -27,10 +35,6 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.apache.xmlbeans.XmlCursor; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRst; -import javax.xml.namespace.QName; -import java.io.FileOutputStream; -import java.io.IOException; - /** * */ @@ -144,4 +148,24 @@ public class TestSXSSFCell extends BaseTestCell { assertEquals("expected xml:spaces=\"preserve\" \"" + str + "\"", "preserve", t); } } + + public void testBug55658SetNumericValue(){ + Workbook wb = new SXSSFWorkbook(); + Sheet sh = wb.createSheet(); + Row row = sh.createRow(0); + Cell cell = row.createCell(0); + cell.setCellValue(Integer.valueOf(23)); + + cell.setCellValue("some"); + + cell = row.createCell(1); + cell.setCellValue(Integer.valueOf(23)); + + cell.setCellValue("24"); + + wb = _testDataProvider.writeOutAndReadBack(wb); + + assertEquals("some", wb.getSheetAt(0).getRow(0).getCell(0).getStringCellValue()); + assertEquals("24", wb.getSheetAt(0).getRow(0).getCell(1).getStringCellValue()); + } } |