Allow formatting of formula error cells, giving back the error string that Excel shows #55729
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1537552 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
d08ab9dc0d
commit
01b276b2f3
@ -829,6 +829,8 @@ public class DataFormatter {
|
||||
return String.valueOf(cell.getBooleanCellValue());
|
||||
case Cell.CELL_TYPE_BLANK :
|
||||
return "";
|
||||
case Cell.CELL_TYPE_ERROR:
|
||||
return FormulaError.forInt(cell.getErrorCellValue()).getString();
|
||||
}
|
||||
throw new RuntimeException("Unexpected celltype (" + cellType + ")");
|
||||
}
|
||||
|
@ -28,6 +28,7 @@ import java.util.Locale;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||
import org.apache.poi.hssf.usermodel.TestHSSFDataFormatter;
|
||||
|
||||
/**
|
||||
@ -491,6 +492,22 @@ public class TestDataFormatter extends TestCase {
|
||||
assertEquals(" - ", dfUS.formatRawCellContents(0.0, -1, "_-* #,##0.00_-;-* #,##0.00_-;_-* \"-\"??_-;_-@_-"));
|
||||
assertEquals(" $- ", dfUS.formatRawCellContents(0.0, -1, "_-$* #,##0.00_-;-$* #,##0.00_-;_-$* \"-\"??_-;_-@_-"));
|
||||
}
|
||||
|
||||
public void testErrors() {
|
||||
DataFormatter dfUS = new DataFormatter(Locale.US, true);
|
||||
|
||||
// Create a spreadsheet with some formula errors in it
|
||||
Workbook wb = new HSSFWorkbook();
|
||||
Sheet s = wb.createSheet();
|
||||
Row r = s.createRow(0);
|
||||
Cell c = r.createCell(0, Cell.CELL_TYPE_ERROR);
|
||||
|
||||
c.setCellErrorValue(FormulaError.DIV0.getCode());
|
||||
assertEquals(FormulaError.DIV0.getString(), dfUS.formatCellValue(c));
|
||||
|
||||
c.setCellErrorValue(FormulaError.REF.getCode());
|
||||
assertEquals(FormulaError.REF.getString(), dfUS.formatCellValue(c));
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO Fix these so that they work
|
||||
|
Loading…
Reference in New Issue
Block a user