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

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

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

Cell.getColumnIndex介绍

[英]Returns column index of this cell
[中]返回此单元格的列索引

代码示例

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

/**
 * Create a new CellAddress object.
 *
 * @param cell the Cell to get the location of
 */
public CellAddress(Cell cell) {
  this(cell.getRowIndex(), cell.getColumnIndex());
}

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

public CellReference(Cell cell) {
  this(cell.getRowIndex(), cell.getColumnIndex(), false, false);
}

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

public String getContents() {
 try {
  Object value = getValue();
  if ( value == null ) {
   return null;
  }
  return value.toString();
 } catch ( Exception e ) {
  throw new RuntimeException( "Unable to get string content of cell ("
   + cell.getColumnIndex() + ", " + cell.getRowIndex() + ")", e );
 }
}

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

/**
 * Helper for {@link #updateColumnWidths(Row)}.
 * Implicitly track the columns corresponding to the cells in row.
 * If all columns in the row are already tracked, this call does nothing.
 * Explicitly untracked columns will not be tracked.
 *
 * @param row the row containing cells to implicitly track the columns
 * @since 3.14beta1
 */
private void implicitlyTrackColumnsInRow(Row row) {
  // track new columns
  if (trackAllColumns) {
    // if column is not tracked, implicitly track the column if trackAllColumns is True and column has not been explicitly untracked 
    for (final Cell cell : row) {
      final int column = cell.getColumnIndex();
      implicitlyTrackColumn(column);
    }
  }
}

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

/**
 * Determines if the given {@link Cell} lies within the bounds 
 * of this range.  
 * <p>NOTE: It is up to the caller to ensure the reference is 
 * for the correct sheet, since this instance doesn't have a sheet reference.
 *
 * @param cell the Cell to check
 * @return True if the cell lies within the bounds, false otherwise.
 * @see #intersects(CellRangeAddressBase) for checking if two ranges overlap
 */
public boolean isInRange(Cell cell) {
  return isInRange(cell.getRowIndex(), cell.getColumnIndex());
}

代码示例来源:origin: kiegroup/optaplanner

protected long readLongCell(Cell cell) {
  double d = cell.getNumericCellValue();
  long l = (long) d;
  if (d - (double) l != 0.0) {
    throw new IllegalArgumentException("The keyCell (" + cell.getRow().getRowNum() + ","
        + cell.getColumnIndex() + ") with value (" + d + ") is expected to be a long.");
  }
  return l;
}

代码示例来源:origin: kiegroup/optaplanner

protected double readDoubleParameter(Row row, String key) {
    Cell keyCell = row.getCell(0);
    if (!key.equals(keyCell.getStringCellValue())) {
      throw new IllegalArgumentException("The keyCell (" + keyCell.getRow().getRowNum() + ","
          + keyCell.getColumnIndex() + ") with value (" + keyCell.getStringCellValue()
          + ") is expected to have the key (" + key + ")");
    }
    Cell valueCell = row.getCell(1);
    return valueCell.getNumericCellValue();
  }
}

代码示例来源:origin: kiegroup/optaplanner

protected String readStringParameter(Row row, String key) {
  Cell keyCell = row.getCell(0);
  if (!key.equals(keyCell.getStringCellValue())) {
    throw new IllegalArgumentException("The keyCell (" + keyCell.getRow().getRowNum() + ","
        + keyCell.getColumnIndex() + ") with value (" + keyCell.getStringCellValue()
        + ") is expected to have the key (" + key + ")");
  }
  Cell valueCell = row.getCell(1);
  return valueCell.getStringCellValue();
}

代码示例来源:origin: kiegroup/optaplanner

protected void assertCellConstant(Cell cell, String constant) {
  if (!constant.equals(cell.getStringCellValue())) {
    throw new IllegalArgumentException("The cell (" + cell.getRow().getRowNum() + ","
        + cell.getColumnIndex() + ") with value (" + cell.getStringCellValue()
        + ") is expected to have the constant (" + constant + ")");
  }
}

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

public Object getValue() {
 try {
  switch ( getType() ) {
   case BOOLEAN_FORMULA:
   case BOOLEAN:
    return Boolean.valueOf( cell.getBooleanCellValue() );
   case DATE_FORMULA:
   case DATE:
    // Timezone conversion needed since POI doesn't support this apparently
    //
    long time = cell.getDateCellValue().getTime();
    long tzOffset = TimeZone.getDefault().getOffset( time );
    return new Date( time + tzOffset );
   case NUMBER_FORMULA:
   case NUMBER:
    return Double.valueOf( cell.getNumericCellValue() );
   case STRING_FORMULA:
   case LABEL:
    return cell.getStringCellValue();
   case EMPTY:
   default:
    return null;
  }
 } catch ( Exception e ) {
  throw new RuntimeException( "Unable to get value of cell ("
   + cell.getColumnIndex() + ", " + cell.getRowIndex() + ")", e );
 }
}

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

final int column = cell.getColumnIndex();

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

/**
 * Remove the Cell from this row.
 *
 * @param cell the cell to remove
 */
@Override
public void removeCell(Cell cell) {
  if (cell.getRow() != this) {
    throw new IllegalArgumentException("Specified cell does not belong to this row");
  }
  XSSFCell xcell = (XSSFCell)cell;
  if(xcell.isPartOfArrayFormulaGroup()) {
    xcell.notifyArrayFormulaChanging();
  }
  if(cell.getCellType() == CellType.FORMULA) {
    _sheet.getWorkbook().onDeleteFormula(xcell);
  }
  // Performance optimization for bug 57840: explicit boxing is slightly faster than auto-unboxing, though may use more memory
  final Integer colI = Integer.valueOf(cell.getColumnIndex()); // NOSONAR
  _cells.remove(colI);
}

代码示例来源: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: kiegroup/optaplanner

private void readTimeslotHours() {
    columnIndexToStartTimeMap.clear();
    columnIndexToEndTimeMap.clear();
    StreamSupport.stream(currentRow.spliterator(), false)
        .forEach(cell -> {
          if (!cell.getStringCellValue().isEmpty() && !cell.getStringCellValue().equals("Room")) {
            String[] startAndEndTimeStringArray = cell.getStringCellValue().split("-");
            try {
              columnIndexToStartTimeMap.put(cell.getColumnIndex(),
                  LocalTime.parse(startAndEndTimeStringArray[0], TIME_FORMATTER));
              columnIndexToEndTimeMap.put(cell.getColumnIndex(), LocalTime.parse(startAndEndTimeStringArray[1],
                  TIME_FORMATTER));
            } catch (DateTimeParseException e) {
              throw new IllegalStateException(currentPosition() + ": The startTime (" + startAndEndTimeStringArray[0]
                  + ") or endTime (" + startAndEndTimeStringArray[1]
                  + ") doesn't parse as a time.", e);
            }
          }
        });
  }
}

代码示例来源: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-ooxml

for (final Cell cell : row) {
  final CellKey key = new CellKey(rowNum, cell.getColumnIndex());
  final EvaluationCell evalcell = new XSSFEvaluationCell((XSSFCell) cell, this);
  _cellCache.put(key, evalcell);

代码示例来源: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: pentaho/pentaho-kettle

/**
 * Set specified cell format
 *
 * @param excelFieldFormat the specified format
 * @param cell             the cell to set up format
 */
private void setDataFormat( String excelFieldFormat, Cell cell ) {
 if ( log.isDebug() ) {
  logDebug( BaseMessages.getString( PKG, "ExcelWriterStep.Log.SetDataFormat", excelFieldFormat, CellReference.convertNumToColString( cell.getColumnIndex() ), cell.getRowIndex() ) );
 }
 DataFormat format = data.wb.createDataFormat();
 short formatIndex = format.getFormat( excelFieldFormat );
 CellStyle style = data.wb.createCellStyle();
 style.cloneStyleFrom( cell.getCellStyle() );
 style.setDataFormat( formatIndex );
 cell.setCellStyle( style );
}

相关文章