/** * Creates a XSSFFormulaEvaluator, the object that evaluates formula cells. * * @return a XSSFFormulaEvaluator instance */ @Override public XSSFFormulaEvaluator createFormulaEvaluator() { return new XSSFFormulaEvaluator(workbook); }
/** * Loops over all cells in all sheets of the supplied * workbook. * For cells that contain formulas, their formulas are * evaluated, and the results are saved. These cells * remain as formula cells. * For cells that do not contain formulas, no changes * are made. * This is a helpful wrapper around looping over all * cells, and calling evaluateFormulaCell on each one. */ public void evaluateAll() { evaluateAllFormulaCells(_book, this); }
protected CellValue getCellValueAt(int index) { if (index < 0 || index >= numOfCells) { throw new IndexOutOfBoundsException( "Index must be between 0 and " + (numOfCells - 1) + " (inclusive), given: " + index); } int firstRow = cellRangeAddress.getFirstRow(); int firstCol = cellRangeAddress.getFirstColumn(); int lastCol = cellRangeAddress.getLastColumn(); int width = lastCol - firstCol + 1; int rowIndex = firstRow + index / width; int cellIndex = firstCol + index % width; XSSFRow row = sheet.getRow(rowIndex); return (row == null) ? null : evaluator.evaluate(row.getCell(cellIndex)); } }
/** * Returns a formula evaluator that is loaded with the functions that * have been supplied. * * @param fileName Specifies if XSSF or HSSF should be used for * the evaluator * @return A {@link FormulaEvaluator} constructed accordingly */ protected FormulaEvaluator getEvaluator(String fileName) { FormulaEvaluator evaluator; if (fileName.endsWith(".xlsx")) { if(xlsMacroList.size() > 0) { evaluator = XSSFFormulaEvaluator.create((XSSFWorkbook) workbook, null, getFunctions()); } evaluator = new XSSFFormulaEvaluator((XSSFWorkbook) workbook); } else { if(xlsMacroList.size() > 0) { evaluator = HSSFFormulaEvaluator.create((HSSFWorkbook)workbook, null, getFunctions()); } evaluator = new HSSFFormulaEvaluator((HSSFWorkbook) workbook); } return evaluator; }
public ExcelFormulaEvaluator (@Nonnull final Workbook aWB, @Nullable final IStabilityClassifier aStability) { m_aEvaluator = aWB instanceof HSSFWorkbook ? new HSSFFormulaEvaluator ((HSSFWorkbook) aWB, aStability) : XSSFFormulaEvaluator.create ((XSSFWorkbook) aWB, aStability, null); }
} catch (Exception e) { LOG.debug("Failed to get raw cell value, now trying to get typified", e); switch (evaluator.evaluateFormulaCellEnum(cell)) { case BOOLEAN: value = String.valueOf(cell.getBooleanCellValue());
} catch (Exception e) { LOG.debug("Failed to get raw cell value, now trying to get typified", e); switch (evaluator.evaluateFormulaCell(cell)) { case Cell.CELL_TYPE_BOOLEAN: value = String.valueOf(cell.getBooleanCellValue());
public ExcelFormulaEvaluator (@Nonnull final Workbook aWB, @Nullable final IStabilityClassifier aStability) { m_aEvaluator = aWB instanceof HSSFWorkbook ? new HSSFFormulaEvaluator ((HSSFWorkbook) aWB, aStability) : XSSFFormulaEvaluator.create ((XSSFWorkbook) aWB, aStability, null); }
/** * @param stabilityClassifier used to optimise caching performance. Pass <code>null</code> * for the (conservative) assumption that any cell may have its definition changed after * evaluation begins. * @param udfFinder pass <code>null</code> for default (AnalysisToolPak only) */ public static XSSFFormulaEvaluator create(XSSFWorkbook workbook, IStabilityClassifier stabilityClassifier, UDFFinder udfFinder) { return new XSSFFormulaEvaluator(workbook, stabilityClassifier, udfFinder); }
/** * Loops over all cells in all sheets of the supplied * workbook. * For cells that contain formulas, their formulas are * evaluated, and the results are saved. These cells * remain as formula cells. * For cells that do not contain formulas, no changes * are made. * This is a helpful wrapper around looping over all * cells, and calling evaluateFormulaCell on each one. */ public void evaluateAll() { evaluateAllFormulaCells(_book, this); }
protected CellValue getCellValueAt(int index) { if (index < 0 || index >= numOfCells) { throw new IndexOutOfBoundsException( "Index must be between 0 and " + (numOfCells - 1) + " (inclusive), given: " + index); } int firstRow = cellRangeAddress.getFirstRow(); int firstCol = cellRangeAddress.getFirstColumn(); int lastCol = cellRangeAddress.getLastColumn(); int width = lastCol - firstCol + 1; int rowIndex = firstRow + index / width; int cellIndex = firstCol + index % width; XSSFRow row = sheet.getRow(rowIndex); return (row == null) ? null : evaluator.evaluate(row.getCell(cellIndex)); } }
@Override protected FormulaEvaluator doWithXSSFWorkbook(XSSFWorkbook workbook) { return new XSSFFormulaEvaluator(workbook); } }.execute();
private Workbook getWorkBook() throws IOException { Workbook excelWorkbook; String extension = file.getName().toUpperCase(ENGLISH); try (FileInputStream excelFile = new FileInputStream(file)) { if (extension.endsWith(Extension.XLSX.value) || extension.endsWith(Extension.XLSM.value)) { excelWorkbook = new XSSFWorkbook(excelFile); XSSFFormulaEvaluator.evaluateAllFormulaCells(excelWorkbook); } else if (extension.endsWith(Extension.XLS.value)) { excelWorkbook = new HSSFWorkbook(excelFile); HSSFFormulaEvaluator.evaluateAllFormulaCells(excelWorkbook); } else { FileFormatException e = new FileFormatException(format("%s is not a valid excel file.", file.getName())); LOGGER.error(e.getMessage()); throw e; } } catch (Exception e) { LOGGER.error(e.getMessage()); throw e; } return excelWorkbook; }
/** * @param stabilityClassifier used to optimise caching performance. Pass <code>null</code> * for the (conservative) assumption that any cell may have its definition changed after * evaluation begins. * @param udfFinder pass <code>null</code> for default (AnalysisToolPak only) */ public static XSSFFormulaEvaluator create(XSSFWorkbook workbook, IStabilityClassifier stabilityClassifier, UDFFinder udfFinder) { return new XSSFFormulaEvaluator(workbook, stabilityClassifier, udfFinder); }
/** * @param stabilityClassifier used to optimise caching performance. Pass <code>null</code> * for the (conservative) assumption that any cell may have its definition changed after * evaluation begins. * @param udfFinder pass <code>null</code> for default (AnalysisToolPak only) */ public static XSSFFormulaEvaluator create(XSSFWorkbook workbook, IStabilityClassifier stabilityClassifier, UDFFinder udfFinder) { return new XSSFFormulaEvaluator(workbook, stabilityClassifier, udfFinder); }
/** * Creates a XSSFFormulaEvaluator, the object that evaluates formula cells. * * @return a XSSFFormulaEvaluator instance */ @Override public XSSFFormulaEvaluator createFormulaEvaluator() { return new XSSFFormulaEvaluator(workbook); }
/** * Creates a XSSFFormulaEvaluator, the object that evaluates formula cells. * * @return a XSSFFormulaEvaluator instance */ public XSSFFormulaEvaluator createFormulaEvaluator() { return new XSSFFormulaEvaluator(workbook); }