for(Cell cell : row) { if(cell.getCellType() == Cell.CELL_TYPE_FORMULA) { System.out.println("Formula is " + cell.getCellFormula()); switch(cell.getCachedFormulaResultType()) { case Cell.CELL_TYPE_NUMERIC: System.out.println("Last evaluated as: " + cell.getNumericCellValue()); break; case Cell.CELL_TYPE_STRING: System.out.println("Last evaluated as \"" + cell.getRichStringCellValue() + "\""); break; } } }
outputQuotedString(cell.getCellFormula()); _out.write("</f>"); switch (cell.getCachedFormulaResultType()) {
protected void adjustCellReferencesInsideFormula(Cell cell, Sheet destSheet, int deltaX, int deltaY){ XSSFWorkbook hostWorkbook = (XSSFWorkbook) destSheet.getWorkbook(); XSSFEvaluationWorkbook fpb = XSSFEvaluationWorkbook.create(hostWorkbook); Ptg[] ptgs = FormulaParser.parse(cell.getCellFormula(), fpb, FormulaType.CELL, 0); int destSheetIndex = hostWorkbook.getSheetIndex(destSheet); if(adjustInBothDirections(ptgs, destSheetIndex, deltaX, deltaY)) cell.setCellFormula(FormulaRenderer.toFormulaString(fpb, ptgs)); } }
String contents = cell.getCellFormula(); checkMaxTextSize(text, contents); text.append(contents);
break; case FORMULA: String oldFormula = srcCell.getCellFormula(); destCell.setCellFormula(oldFormula); break;
if (cellType == CellType.FORMULA) { if (evaluator == null) { return cell.getCellFormula();
break; case FORMULA: setCellFormula(srcCell.getCellFormula()); break; case BLANK:
/** * Checks if cell content matches for formula. */ private void isCellContentMatchesForFormula(Locator loc1, Locator loc2) { // TODO: actually evaluate the formula / NPE checks String form1 = loc1.cell.getCellFormula(); String form2 = loc2.cell.getCellFormula(); if (!form1.equals(form2)) { addMessage(loc1, loc2, CELL_DATA_DOES_NOT_MATCH, form1, form2); } }
@Nullable public static String getCellFormula (@Nullable final Cell aCell) { if (aCell != null) try { return aCell.getCellFormula (); } catch (final RuntimeException ex) { // fall through s_aLogger.warn ("Failed to get cell formula: " + ex.getMessage ()); } return null; }
@Nullable public static String getCellFormula (@Nullable final Cell aCell) { if (aCell != null) try { return aCell.getCellFormula (); } catch (final RuntimeException ex) { // fall through LOGGER.warn ("Failed to get cell formula: " + ex.getMessage ()); } return null; }
public TD(Cell cell, TR tr, COL col) { this.tr = tr; this.col = col; this.cell = cell; if (cell != null && cell.getCellType() == Cell.CELL_TYPE_FORMULA) { isFormula = true; formula = cell.getCellFormula().replace("$", ""); valuePresent = false; } if (col.gen) { valuePresent = false; } }
public TD(Cell cell, TR tr, COL col) { this.tr = tr; this.col = col; this.cell = cell; if (cell != null && cell.getCellType() == Cell.CELL_TYPE_FORMULA) { isFormula = true; formula = cell.getCellFormula().replace("$", ""); valuePresent = false; } if (col.gen) { valuePresent = false; } }
public static void copyCellFormula(Workbook workbook, int sheetIndex, int rowIndex, int sourceColumnIndex, int destinationColumnIndex){ XSSFEvaluationWorkbook formulaParsingWorkbook = XSSFEvaluationWorkbook.create((XSSFWorkbook) workbook); SharedFormula sharedFormula = new SharedFormula(SpreadsheetVersion.EXCEL2007); Sheet sheet = workbook.getSheetAt(sheetIndex); Row lookupRow = sheet.getRow(rowIndex); Cell sourceCell = lookupRow.getCell(sourceColumnIndex); Ptg[] sharedFormulaPtg = FormulaParser.parse(sourceCell.getCellFormula(), formulaParsingWorkbook, FormulaType.CELL, sheetIndex); Ptg[] convertedFormulaPtg = sharedFormula.convertSharedFormulas(sharedFormulaPtg, 0, 1); Cell destinationCell = lookupRow.createCell(destinationColumnIndex); destinationCell.setCellFormula(FormulaRenderer.toFormulaString(formulaParsingWorkbook, convertedFormulaPtg)); }
@SuppressWarnings("deprecation") @Override public String getFormula(int row, int column) { Cell cell = getCell(row, column); return cell.getCellType() == CellType.FORMULA ? cell.getCellFormula() : null; }
public static String getCellValue(Cell cell) { if (cell == null) return ""; switch (cell.getCellType()) { case Cell.CELL_TYPE_STRING: return df.formatCellValue(cell).trim(); case Cell.CELL_TYPE_NUMERIC: return df.formatCellValue(cell).trim(); case Cell.CELL_TYPE_BOOLEAN: return df.formatCellValue(cell).trim(); case Cell.CELL_TYPE_FORMULA: return (cell.getCellFormula().contains("[") && cell.getCellFormula().contains("]")) ? null : df.formatCellValue(cell, evaluator).trim(); case Cell.CELL_TYPE_BLANK: return ""; default: return null; } }
private String cellFormula() { Cell cell = getCell(); return cell.getCellType() == CellType.FORMULA ? cell.getCellFormula() : null; }
CellReference cellReference = new CellReference("B3"); Row row = sheet.getRow(cellReference.getRow()); Cell cell = row.getCell(cellReference.getCol()); String formula = cell.getCellFormula();
private static String getStringValue( Cell cell, DecimalFormat decimalFormat) { switch (cell.getCellTypeEnum()) { case NUMERIC: return getNumberTypeStringValue(cell, decimalFormat); case STRING: return cell.getStringCellValue(); case FORMULA: return cell.getCellFormula(); case BOOLEAN: return String.valueOf(cell.getBooleanCellValue()); default: return ""; } }
@Override public Cell adapt(org.apache.poi.ss.usermodel.Cell cell) { if (cell.getCachedFormulaResultType() == CELL_TYPE_ERROR) return new ErrorCell(cell.getErrorCellValue()); return new FormulaCell(cell.getCellFormula()); } },
protected void adjustCellReferencesInsideFormula(Cell cell, Sheet destSheet, int deltaX, int deltaY){ XSSFWorkbook hostWorkbook = (XSSFWorkbook) destSheet.getWorkbook(); XSSFEvaluationWorkbook fpb = XSSFEvaluationWorkbook.create(hostWorkbook); Ptg[] ptgs = FormulaParser.parse(cell.getCellFormula(), fpb, FormulaType.CELL, 0); int destSheetIndex = hostWorkbook.getSheetIndex(destSheet); if(adjustInBothDirections(ptgs, destSheetIndex, deltaX, deltaY)) cell.setCellFormula(FormulaRenderer.toFormulaString(fpb, ptgs)); } }