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
This commit is contained in:
Dominik Stadler 2013-10-16 19:47:21 +00:00
parent 9d98d6e309
commit 3b4538cfb4
2 changed files with 50 additions and 7 deletions

View File

@ -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;

View File

@ -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());
}
}