Fixed switch case indentations and added if condition to check if the cellType is FORMULA or not
@@ -48,7 +48,7 @@ public class CellValueAndNotFormulaHelper {
}
public Object getCellValueByEvaluatingFormula(String fileLocation, String cellLocation) throws IOException {
- Object cellValue;
+ Object cellValue = new Object();
FileInputStream inputStream = new FileInputStream(new File(fileLocation));
Workbook workbook = new XSSFWorkbook(inputStream);
@@ -61,6 +61,7 @@ public class CellValueAndNotFormulaHelper {
Row row = sheet.getRow(cellAddress.getRow());
Cell cell = row.getCell(cellAddress.getColumn());
+ if (cell.getCellType() == CellType.FORMULA) {
switch (evaluator.evaluateFormulaCell(cell)) {
case BOOLEAN:
cellValue = cell.getBooleanCellValue();
@@ -74,6 +75,7 @@ public class CellValueAndNotFormulaHelper {
default:
cellValue = null;
}
+ }
workbook.close();
return cellValue;
