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

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

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

Cell.getSheet介绍

[英]Returns the sheet this cell belongs to
[中]返回此单元格所属的工作表

代码示例

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

/**
 * 克隆新的{@link CellStyle}
 * 
 * @param cell 单元格
 * @param cellStyle 被复制的样式
 * @return {@link CellStyle}
 */
public static CellStyle cloneCellStyle(Cell cell, CellStyle cellStyle) {
  return cloneCellStyle(cell.getSheet().getWorkbook(), cellStyle);
}

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

/**
 * 克隆新的{@link CellStyle}
 * 
 * @param cell 单元格
 * @param cellStyle 被复制的样式
 * @return {@link CellStyle}
 */
public static CellStyle cloneCellStyle(Cell cell, CellStyle cellStyle) {
  return cloneCellStyle(cell.getSheet().getWorkbook(), cellStyle);
}

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

/**
 * Take a cell, and apply a font to it
 *
 * @param cell the cell to set the alignment for
 * @param font The Font that you want to set.
 * @throws IllegalArgumentException if <tt>font</tt> and <tt>cell</tt> do not belong to the same workbook
 */
public static void setFont(Cell cell, Font font) {
  // Check if font belongs to workbook
  Workbook wb = cell.getSheet().getWorkbook();
  final int fontIndex = font.getIndexAsInt();
  if (!wb.getFontAt(fontIndex).equals(font)) {
    throw new IllegalArgumentException("Font does not belong to this workbook");
  }
  // Check if cell belongs to workbook
  // (checked in setCellStyleProperty)
  setCellStyleProperty(cell, FONT, fontIndex);
}

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

@Override
public CellRange<XSSFCell> removeArrayFormula(Cell cell) {
  if (cell.getSheet() != this) {
    throw new IllegalArgumentException("Specified cell does not belong to this sheet.");
  }
  for (CellRangeAddress range : arrayFormulas) {
    if (range.isInRange(cell)) {
      arrayFormulas.remove(range);
      CellRange<XSSFCell> cr = getCellRange(range);
      for (XSSFCell c : cr) {
        c.setCellType(CellType.BLANK);
      }
      return cr;
    }
  }
  String ref = ((XSSFCell)cell).getCTCell().getR();
  throw new IllegalArgumentException("Cell " + ref + " is not part of an array formula.");
}

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

public static CellReference getRef(Cell cell) {
  return new CellReference(cell.getSheet().getSheetName(), cell.getRowIndex(), cell.getColumnIndex(), false, false);
}

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

/**
 * Calls {@link #getRange(Table, CellReference)}.  Use that instead for performance.
 * @param table
 * @param cell
 * @return default is unimplemented/null
 * @see #getRange(Table, CellReference)
 */
public final CellRangeAddressBase getRange(Table table, Cell cell) {
  if (cell == null) return null;
  return getRange(table, new CellReference(cell.getSheet().getSheetName(), cell.getRowIndex(), cell.getColumnIndex(), true, true));
}

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

/**
 * checks if the given cell is part of the table.  Includes checking that they are on the same sheet.
 * @param cell
 * @return true if the table and cell are on the same sheet and the cell is within the table range.
 * @since 3.17 beta 1
 * @see #contains(CellReference) (prefered, faster execution and handles undefined cells)
 */
default boolean contains(Cell cell) {
  if (cell == null) return false;
  return contains(new CellReference(cell.getSheet().getSheetName(), cell.getRowIndex(), cell.getColumnIndex(), true, true));
}

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

@Override
public CellRange<HSSFCell> removeArrayFormula(Cell cell) {
  if (cell.getSheet() != this) {
    throw new IllegalArgumentException("Specified cell does not belong to this sheet.");
  }
  CellValueRecordInterface rec = ((HSSFCell) cell).getCellValueRecord();
  if (!(rec instanceof FormulaRecordAggregate)) {
    String ref = new CellReference(cell).formatAsString();
    throw new IllegalArgumentException("Cell " + ref + " is not part of an array formula.");
  }
  FormulaRecordAggregate fra = (FormulaRecordAggregate) rec;
  CellRangeAddress range = fra.removeArrayFormula(cell.getRowIndex(), cell.getColumnIndex());
  CellRange<HSSFCell> result = getCellRange(range);
  // clear all cells in the range
  for (Cell c : result) {
    c.setCellType(CellType.BLANK);
  }
  return result;
}

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

public static void cloneCellContent(Cell srcCell, Cell destCell, Map<Integer, CellStyle> styleMap) {   
   if(styleMap != null) {   
     if(srcCell.getSheet().getWorkbook() == destCell.getSheet().getWorkbook()){   
       destCell.setCellStyle(srcCell.getCellStyle());   
     } else {
       CellStyle newCellStyle = styleMap.get(stHashCode);   
       if(newCellStyle == null){   
         newCellStyle = destCell.getSheet().getWorkbook().createCellStyle();   
         newCellStyle.cloneStyleFrom(srcCell.getCellStyle());   
         styleMap.put(stHashCode, newCellStyle);

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

/**
 * A range is returned only for the part of the table matching this enum instance and containing the given cell.
 * Null is returned for all other cases, such as:
 * <ul>
 * <li>Cell on a different sheet than the table
 * <li>Cell outside the table
 * <li>this Enum part is not included in the table (i.e. no header/totals row)
 * <li>this Enum is for a table part not yet implemented in POI, such as pivot table elements
 * </ul>
 * The returned range can be used to determine how style options may or may not apply to this cell.
 * For example, {@link #wholeTable} borders only apply to the outer boundary of a table, while the
 * rest of the styling, such as font and color, could apply to all the interior cells as well.
 * 
 * @param table table to evaluate
 * @param cell to evaluate 
 * @return range in the table representing this class of cells, if it contains the given cell, or null if not applicable.
 * Stripe style types return only the stripe range containing the given cell, or null.
 */
public CellRangeAddressBase appliesTo(Table table, Cell cell) {
  if (cell == null) return null;
  return appliesTo(table, new CellReference(cell.getSheet().getSheetName(), cell.getRowIndex(), cell.getColumnIndex(), true, true));
}

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

Workbook workbook = cell.getSheet().getWorkbook();
CellStyle originalStyle = cell.getCellStyle();
CellStyle newStyle = null;

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

Sheet sheet = cell.getSheet();
Workbook wb = sheet.getWorkbook();
Row row = cell.getRow();

代码示例来源:origin: net.sf.jxls/jxls-core

private void setCellValue(Cell cell, String value) {
  if (value == null || value.length() == 0) {
    cell.getPoiCell().setCellType( org.apache.poi.ss.usermodel.Cell.CELL_TYPE_BLANK );
  } else {
    cell.getPoiCell().setCellValue(cell.getPoiCell().getSheet().getWorkbook().getCreationHelper().createRichTextString(value));
  }
}

代码示例来源:origin: com.sqlapp/sqlapp-core

private static CellValue getEvaluatedCellValue(Cell cell){
  Workbook book = cell.getSheet().getWorkbook();
  CreationHelper helper = book.getCreationHelper();
  FormulaEvaluator evaluator = helper.createFormulaEvaluator();
  CellValue value = evaluator.evaluate(cell);
  return value;
}

代码示例来源:origin: openl-tablets/openl-tablets

/**
 * Evaluates formula in the cell to get new cell value.
 */
public static void evaluateFormula(Cell cell) throws Exception {
  FormulaEvaluator formulaEvaluator = cell.getSheet().getWorkbook()
    .getCreationHelper().createFormulaEvaluator();
  formulaEvaluator.evaluateFormulaCell(cell);
}

代码示例来源:origin: com.b2international.snowowl/com.b2international.snowowl.datastore.server

/**
 * Returns true if the cell (NOT the text inside) is set to bold.
 * @param cell
 * @return
 */
public static boolean isBold(Cell cell) {
  CellStyle style = cell.getCellStyle();
  Workbook workBook = cell.getSheet().getWorkbook();
  Font font = workBook.getFontAt(style.getFontIndex());
  XSSFFont xssfFont = (XSSFFont) font;
  return xssfFont.getBold();
}

代码示例来源:origin: hyberbin/J-Excel

public void outputIntAdapter(DataBean dataBean, Object fieldValue, String fieldName,Cell cell) throws AdapterException {
  log.debug("in DefaultOutputAdapter:outputIntAdapter fieldName:{} fieldValue:{}",fieldName,fieldValue);
  if(ObjectHelper.isNullOrEmptyString(fieldValue)) return;
  Workbook workbook = cell.getSheet().getWorkbook();
  CellStyle cellStyle = workbook.createCellStyle();
  CreationHelper createHelper = workbook.getCreationHelper();
  cellStyle.setDataFormat(createHelper.createDataFormat().getFormat("#"));
  cell.setCellValue(NumberUtils.format(fieldValue,0));
  cell.setCellStyle(cellStyle);
}

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

/**
 * checks if the given cell is part of the table.  Includes checking that they are on the same sheet.
 * @param cell
 * @return true if the table and cell are on the same sheet and the cell is within the table range.
 * @since 3.17 beta 1
 * @see #contains(CellReference) (prefered, faster execution and handles undefined cells)
 */
default boolean contains(Cell cell) {
  if (cell == null) return false;
  return contains(new CellReference(cell.getSheet().getSheetName(), cell.getRowIndex(), cell.getColumnIndex(), true, true));
}

代码示例来源: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: org.osgl/excel-reader

public void onReadCellException(Exception e, Cell cell) {
  String errorMessage = S.fmt("Error reading cell value: %s@[%s]", cell.getAddress(), cell.getSheet().getSheetName());
  if (isStrict()) {
    throw new ExcelReadException(e, errorMessage);
  }
  LOGGER.warn(e, errorMessage);
}

相关文章