* @author James May (james dot may at fmr dot com)\r
*\r
*/\r
-public class DataFormatter {\r
+public final class DataFormatter {\r
\r
/** Pattern to find a number format: "0" or "#" */\r
private static final Pattern numPattern = Pattern.compile("[0#]+");\r
* @param evaluator The FormulaEvaluator (can be null)\r
* @return a string value of the cell\r
*/\r
- public String formatCellValue(Cell cell,\r
- FormulaEvaluator evaluator) throws IllegalArgumentException {\r
+ public String formatCellValue(Cell cell, FormulaEvaluator evaluator) {\r
\r
if (cell == null) {\r
return "";\r
}\r
\r
int cellType = cell.getCellType();\r
- if (evaluator != null && cellType == Cell.CELL_TYPE_FORMULA) {\r
- try {\r
- cellType = evaluator.evaluateFormulaCell(cell);\r
- } catch (RuntimeException e) {\r
- throw new RuntimeException("Did you forget to set the current" +\r
- " row on the FormulaEvaluator?", e);\r
+ if (cellType == Cell.CELL_TYPE_FORMULA) {\r
+ if (evaluator == null) {\r
+ return cell.getCellFormula();\r
}\r
+ cellType = evaluator.evaluateFormulaCell(cell);\r
}\r
- switch (cellType)\r
- {\r
- case Cell.CELL_TYPE_FORMULA :\r
- // should only occur if evaluator is null\r
- return cell.getCellFormula();\r
-\r
+ switch (cellType) {\r
case Cell.CELL_TYPE_NUMERIC :\r
\r
if (DateUtil.isCellDateFormatted(cell)) {\r
package org.apache.poi.ss.usermodel;
+import java.util.Date;
+
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFRichTextString;
import org.apache.poi.hssf.usermodel.HSSFSheet;
boolean getBooleanCellValue();
double getNumericCellValue();
+ /**
+ * get the value of the cell as a date. For strings we throw an exception.
+ * For blank cells we return a null.
+ */
+ Date getDateCellValue();
HSSFRichTextString getRichStringCellValue();
void setCellType(int cellType);