org.apache.poi.ss.usermodel.Cell.setCellFormula()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(7.3k)|赞(0)|评价(0)|浏览(529)

本文整理了Java中org.apache.poi.ss.usermodel.Cell.setCellFormula()方法的一些代码示例,展示了Cell.setCellFormula()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Cell.setCellFormula()方法的具体详情如下:
包路径:org.apache.poi.ss.usermodel.Cell
类名称:Cell
方法名:setCellFormula

Cell.setCellFormula介绍

[英]Sets formula for this cell.

Note, this method only sets the formula string and does not calculate the formula value. To set the precalculated value use #setCellValue(double) or #setCellValue(String)
[中]设置此单元格的公式。
注意,此方法仅设置公式字符串,不计算公式值。要设置预先计算的值,请使用#setCellValue(双精度)或#setCellValue(字符串)

代码示例

代码示例来源:origin: org.apache.poi/poi

/**
 * Sets the cell value using object type information.
 *
 * @param cell  cell to change
 * @param value value to set
 */
private void setCellValue(Cell cell, Object value) {
  if (value == null || cell == null) {
    return;
  }
  if (value instanceof Number) {
    double doubleValue = ((Number) value).doubleValue();
    cell.setCellValue(doubleValue);
  } else if (value instanceof Date) {
    cell.setCellValue((Date) value);
  } else if (value instanceof Calendar) {
    cell.setCellValue((Calendar) value);
  } else if (isFormulaDefinition(value)) {
    cell.setCellFormula(getFormula(value));
  } else {
    cell.setCellValue(value.toString());
  }
}

代码示例来源:origin: looly/hutool

}else if (value instanceof FormulaCellValue) {
  cell.setCellFormula(((FormulaCellValue)value).getValue());
} else if (value instanceof Date) {
  if (null != styleSet && null != styleSet.getCellStyleForDate()) {

代码示例来源:origin: looly/hutool

}else if (value instanceof FormulaCellValue) {
  cell.setCellFormula(((FormulaCellValue)value).getValue());
} else if (value instanceof Date) {
  if (null != styleSet && null != styleSet.getCellStyleForDate()) {

代码示例来源:origin: org.apache.poi/poi-ooxml

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));
  }
}

代码示例来源:origin: org.apache.poi/poi

case FORMULA: 
  String oldFormula = srcCell.getCellFormula();
  destCell.setCellFormula(oldFormula);   
  break;   
default:

代码示例来源:origin: pentaho/pentaho-kettle

cell.setCellFormula( vMeta.getString( v ) );
} else {

代码示例来源:origin: org.apache.poi/poi-excelant

/**
 * Utility method for setting the value of a Cell with a Formula.
 *
 * @param cellName
 * @param formula
 */
public void setFormulaValue(String cellName, String formula) {
  Cell cell = getCell(cellName);
  cell.setCellFormula(formula);
}

代码示例来源:origin: Appendium/objectlabkit

public ExcelCell formula(String formula) {
  currentCell.setCellFormula(formula);
  currentCell.setCellType(CellType.FORMULA);
  return this;
}

代码示例来源:origin: com.phloc/phloc-poi

/**
 * @param sFormula
 *          The formula to be set. May be <code>null</code> to set no formula.
 * @return A new cell in the current row of the current sheet with the passed formula
 */
@Nonnull
public Cell addCellFormula (@Nullable final String sFormula)
{
 final Cell aCell = addCell ();
 aCell.setCellType (CellType.FORMULA);
 aCell.setCellFormula (sFormula);
 return aCell;
}

代码示例来源:origin: stackoverflow.com

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));
}

代码示例来源:origin: com.helger/ph-poi

/**
 * @param sFormula
 *        The formula to be set. May be <code>null</code> to set no formula.
 * @return A new cell in the current row of the current sheet with the passed
 *         formula
 */
@Nonnull
public Cell addCellFormula (@Nullable final String sFormula)
{
 final Cell aCell = addCell ();
 aCell.setCellType (CellType.FORMULA);
 aCell.setCellFormula (sFormula);
 return aCell;
}

代码示例来源:origin: io.github.repir/RepIRTools

public void setAvg(Cell result) {
 if (result.getSheet() == this.start.sheet.sheet) {
   result.setCellFormula(PrintTools.sprintf("AVERAGE(%s)", this));
 } else {
   result.setCellFormula(PrintTools.sprintf("AVERAGE(%s)", this.toSheetString()));
 }
}

代码示例来源:origin: io.github.repir/RepIRTools

public void setSum(Cell result) {
   if (result.getSheet() == this.start.sheet.sheet) {
     result.setCellFormula(PrintTools.sprintf("SUM(%s)", this));
   } else {
     result.setCellFormula(PrintTools.sprintf("SUM(%s)", this.toSheetString()));
   }

  }
}

代码示例来源:origin: Vatavuk/excel-io

@Override
  public Cell attachTo(final Row row) {
    final Cell cell = new EmptyCell(this.position).attachTo(row);
    cell.setCellFormula(this.value);
    return cell;
  }
}

代码示例来源:origin: tobyweston/simple-excel

@Override
public void update(org.apache.poi.ss.usermodel.Cell cell, Workbook workbook) {
  this.getStyle().applyTo(cell, workbook);
  cell.setCellFormula(formula);
}

代码示例来源:origin: stackoverflow.com

XSSFRow r = nfrntSheet.getRow(i);
Cell c = r.createCell(7);
 c.setCellType(XSSFCell.CELL_TYPE_FORMULA);

c.setCellFormula("'Original'!F"+(i+1)+"+'Original'!G"+(i+1)+"*-1");

代码示例来源:origin: stackoverflow.com

XSSFWorkbook wb = new XSSFWorkbook();
   XSSFSheet sheet = wb.createSheet("test");
   Row row = sheet.createRow(0);
   Cell inCell = row.createCell(0);            
   inCell.setCellValue("01.0234500");
   Cell outCell = row.createCell(1);
   FormulaEvaluator fev = wb.getCreationHelper().createFormulaEvaluator();
   String value = inCell.getStringCellValue();            
   outCell.setCellFormula("VALUE(" + value + ")");
   fev.evaluateInCell(outCell);

代码示例来源:origin: ccavanaugh/jgnash

private static void addSummaryCell(final Row row, final int col, final List<CellReference> cellReferenceList, final CellStyle style) {
  final Cell c = row.createCell(col);
  c.setCellType(CellType.FORMULA);
  c.setCellStyle(style);
  c.setCellFormula(buildAddFormula(cellReferenceList));
}

代码示例来源:origin: subtlelib/poi

@SuppressWarnings("UnusedReturnValue") // for consistency with the other methods
private RowContext writeFormula(Formula formula, Style style) {
  checkArgument(formula != null, "Formula is null for column %s", index);
  checkState(totalsData != null, "Please set totals data before rendering totals formula (setTotalsDataBlock(...)");
  String columnIndex = Columns.columnIndexAsLetters(index + 1);
  String totalString = formula.toString() + '(' + columnIndex + totalsData.getStartRowNo()
      + ":"
      + columnIndex + totalsData.getEndRowNo() + ')';
  Cell cell = createCell(1, style);
  cell.setCellFormula(totalString);
  cacheEvaluatedFormula(cell);
  return this;
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.poi

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));
  }
}

相关文章