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 + ")");
}
import junit.framework.TestCase;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.usermodel.TestHSSFDataFormatter;
/**
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