Use Cell rather than HSSFCell cell type constants

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1693642 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Nick Burch 2015-07-31 19:41:43 +00:00
parent 66d370a978
commit 98382860a4

View File

@ -194,17 +194,17 @@ public class HSSFFormulaEvaluator implements FormulaEvaluator, WorkbookEvaluator
} }
switch (cell.getCellType()) { switch (cell.getCellType()) {
case HSSFCell.CELL_TYPE_BOOLEAN: case Cell.CELL_TYPE_BOOLEAN:
return CellValue.valueOf(cell.getBooleanCellValue()); return CellValue.valueOf(cell.getBooleanCellValue());
case HSSFCell.CELL_TYPE_ERROR: case Cell.CELL_TYPE_ERROR:
return CellValue.getError(cell.getErrorCellValue()); return CellValue.getError(cell.getErrorCellValue());
case HSSFCell.CELL_TYPE_FORMULA: case Cell.CELL_TYPE_FORMULA:
return evaluateFormulaCellValue(cell); return evaluateFormulaCellValue(cell);
case HSSFCell.CELL_TYPE_NUMERIC: case Cell.CELL_TYPE_NUMERIC:
return new CellValue(cell.getNumericCellValue()); return new CellValue(cell.getNumericCellValue());
case HSSFCell.CELL_TYPE_STRING: case Cell.CELL_TYPE_STRING:
return new CellValue(cell.getRichStringCellValue().getString()); return new CellValue(cell.getRichStringCellValue().getString());
case HSSFCell.CELL_TYPE_BLANK: case Cell.CELL_TYPE_BLANK:
return null; return null;
} }
throw new IllegalStateException("Bad cell type (" + cell.getCellType() + ")"); throw new IllegalStateException("Bad cell type (" + cell.getCellType() + ")");
@ -228,7 +228,7 @@ public class HSSFFormulaEvaluator implements FormulaEvaluator, WorkbookEvaluator
*/ */
@Override @Override
public int evaluateFormulaCell(Cell cell) { public int evaluateFormulaCell(Cell cell) {
if (cell == null || cell.getCellType() != HSSFCell.CELL_TYPE_FORMULA) { if (cell == null || cell.getCellType() != Cell.CELL_TYPE_FORMULA) {
return -1; return -1;
} }
CellValue cv = evaluateFormulaCellValue(cell); CellValue cv = evaluateFormulaCellValue(cell);
@ -258,7 +258,7 @@ public class HSSFFormulaEvaluator implements FormulaEvaluator, WorkbookEvaluator
return null; return null;
} }
HSSFCell result = (HSSFCell) cell; HSSFCell result = (HSSFCell) cell;
if (cell.getCellType() == HSSFCell.CELL_TYPE_FORMULA) { if (cell.getCellType() == Cell.CELL_TYPE_FORMULA) {
CellValue cv = evaluateFormulaCellValue(cell); CellValue cv = evaluateFormulaCellValue(cell);
setCellValue(cell, cv); setCellValue(cell, cv);
setCellType(cell, cv); // cell will no longer be a formula cell setCellType(cell, cv); // cell will no longer be a formula cell
@ -268,15 +268,15 @@ public class HSSFFormulaEvaluator implements FormulaEvaluator, WorkbookEvaluator
private static void setCellType(Cell cell, CellValue cv) { private static void setCellType(Cell cell, CellValue cv) {
int cellType = cv.getCellType(); int cellType = cv.getCellType();
switch (cellType) { switch (cellType) {
case HSSFCell.CELL_TYPE_BOOLEAN: case Cell.CELL_TYPE_BOOLEAN:
case HSSFCell.CELL_TYPE_ERROR: case Cell.CELL_TYPE_ERROR:
case HSSFCell.CELL_TYPE_NUMERIC: case Cell.CELL_TYPE_NUMERIC:
case HSSFCell.CELL_TYPE_STRING: case Cell.CELL_TYPE_STRING:
cell.setCellType(cellType); cell.setCellType(cellType);
return; return;
case HSSFCell.CELL_TYPE_BLANK: case Cell.CELL_TYPE_BLANK:
// never happens - blanks eventually get translated to zero // never happens - blanks eventually get translated to zero
case HSSFCell.CELL_TYPE_FORMULA: case Cell.CELL_TYPE_FORMULA:
// this will never happen, we have already evaluated the formula // this will never happen, we have already evaluated the formula
} }
throw new IllegalStateException("Unexpected cell value type (" + cellType + ")"); throw new IllegalStateException("Unexpected cell value type (" + cellType + ")");
@ -285,21 +285,21 @@ public class HSSFFormulaEvaluator implements FormulaEvaluator, WorkbookEvaluator
private static void setCellValue(Cell cell, CellValue cv) { private static void setCellValue(Cell cell, CellValue cv) {
int cellType = cv.getCellType(); int cellType = cv.getCellType();
switch (cellType) { switch (cellType) {
case HSSFCell.CELL_TYPE_BOOLEAN: case Cell.CELL_TYPE_BOOLEAN:
cell.setCellValue(cv.getBooleanValue()); cell.setCellValue(cv.getBooleanValue());
break; break;
case HSSFCell.CELL_TYPE_ERROR: case Cell.CELL_TYPE_ERROR:
cell.setCellErrorValue(cv.getErrorValue()); cell.setCellErrorValue(cv.getErrorValue());
break; break;
case HSSFCell.CELL_TYPE_NUMERIC: case Cell.CELL_TYPE_NUMERIC:
cell.setCellValue(cv.getNumberValue()); cell.setCellValue(cv.getNumberValue());
break; break;
case HSSFCell.CELL_TYPE_STRING: case Cell.CELL_TYPE_STRING:
cell.setCellValue(new HSSFRichTextString(cv.getStringValue())); cell.setCellValue(new HSSFRichTextString(cv.getStringValue()));
break; break;
case HSSFCell.CELL_TYPE_BLANK: case Cell.CELL_TYPE_BLANK:
// never happens - blanks eventually get translated to zero // never happens - blanks eventually get translated to zero
case HSSFCell.CELL_TYPE_FORMULA: case Cell.CELL_TYPE_FORMULA:
// this will never happen, we have already evaluated the formula // this will never happen, we have already evaluated the formula
default: default:
throw new IllegalStateException("Unexpected cell value type (" + cellType + ")"); throw new IllegalStateException("Unexpected cell value type (" + cellType + ")");
@ -342,7 +342,7 @@ public class HSSFFormulaEvaluator implements FormulaEvaluator, WorkbookEvaluator
for(Row r : sheet) { for(Row r : sheet) {
for (Cell c : r) { for (Cell c : r) {
if (c.getCellType() == HSSFCell.CELL_TYPE_FORMULA) { if (c.getCellType() == Cell.CELL_TYPE_FORMULA) {
evaluator.evaluateFormulaCell(c); evaluator.evaluateFormulaCell(c);
} }
} }