/** * Create a new CellAddress object. * * @param cell the Cell to get the location of */ public CellAddress(Cell cell) { this(cell.getRowIndex(), cell.getColumnIndex()); }
public CellReference(Cell cell) { this(cell.getRowIndex(), cell.getColumnIndex(), false, false); }
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 ); } }
/** * 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()); }
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 ); } }
public static CellReference getRef(Cell cell) { return new CellReference(cell.getSheet().getSheetName(), cell.getRowIndex(), cell.getColumnIndex(), false, false); }
/** * 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)); }
/** * 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)); }
@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; }
/** * 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)); }
/** * 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 ); }
private static String getCellName(Cell cell) { return CellReference.convertNumToColString(cell.getColumnIndex()) + (cell.getRowIndex() + 1); }
/** * Create a new CellAddress object. * * @param cell the Cell to get the location of */ public CellAddress(Cell cell) { this(cell.getRowIndex(), cell.getColumnIndex()); }
CellRangeAddress getRangeIfMerged(Cell cell, CellRangeAddress[] mergedRanges) { for ( int i = 0; i < mergedRanges.length; i++ ) { CellRangeAddress r = mergedRanges[i]; if (r.isInRange(cell.getRowIndex(), cell.getColumnIndex())) { return r; } } return null; }
private Cell createCell(int cellNo, Row row, CellStyle style, ReportType reportType, ReportAggregation aggregation) { Cell cell = createCell(cellNo, row, style, (String) null); String value = getCellText(reportType, aggregation, cell.getRowIndex(), cell.getColumnIndex()); cell.setCellValue(value); return cell; }
private void fillRuleTotalCondition(Sheet sheet) { assert sheet != null; Cell value = getCell(sheet, RuleSheetFormat.TOTAL_CONDITION, 0, 1); value.setCellStyle(info.optionsStyle); String[] options = TotalConditionKind.getOptions(); value.setCellValue(options[0]); setExplicitListConstraint(sheet, options, value.getRowIndex(), value.getColumnIndex(), value.getRowIndex(), value.getColumnIndex()); }
/** * 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)); }
/** * 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)); }
private void addSumCellToList(Cell cell) { String cellValue = cell.getStringCellValue(); int index = 0; while ((index = indexOfIgnoreCase(cellValue, SUM, index)) != -1) { TemplateSumEntity entity = new TemplateSumEntity(); entity.setCellValue(cellValue); entity.setSumKey(getSumKey(cellValue, index++)); entity.setCol(cell.getColumnIndex()); entity.setRow(cell.getRowIndex()); sumMap.put(entity.getSumKey(), entity); } }
private void addSumCellToList(Cell cell) { String cellValue = cell.getStringCellValue(); int index = 0; while ((index = indexOfIgnoreCase(cellValue, SUM, index)) != -1) { TemplateSumEntity entity = new TemplateSumEntity(); entity.setCellValue(cellValue); entity.setSumKey(getSumKey(cellValue, index++)); entity.setCol(cell.getColumnIndex()); entity.setRow(cell.getRowIndex()); sumMap.put(entity.getSumKey(), entity); } }