本文整理了Java中org.apache.poi.ss.usermodel.Cell.getCellType()
方法的一些代码示例,展示了Cell.getCellType()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Cell.getCellType()
方法的具体详情如下:
包路径:org.apache.poi.ss.usermodel.Cell
类名称:Cell
方法名:getCellType
[英]Return the cell type.
[中]返回单元格类型。
代码示例来源:origin: stackoverflow.com
Cell c = row.getCell(3);
if (c == null || c.getCellType() == Cell.CELL_TYPE_BLANK) {
// This cell is empty
}
代码示例来源:origin: org.apache.poi/poi
private boolean isEmpty(Cell cell) {
return (cell.getCellType() == CellType.BLANK);
}
代码示例来源:origin: org.apache.poi/poi
/**
* Note that this assumes the cell cached value is up to date and in sync with data edits
*
* @param cell The {@link Cell} to check.
* @param type The {@link CellType} to check for.
* @return true if the cell or cached cell formula result type match the given type
*/
public static boolean isType(Cell cell, CellType type) {
final CellType cellType = cell.getCellType();
return cellType == type
|| (cellType == CellType.FORMULA
&& cell.getCachedFormulaResultType() == type
);
}
代码示例来源:origin: org.apache.poi/poi
/**
* Returns the ultimate cell type, following the results of formulas. If
* the cell is a {@link CellType#FORMULA}, this returns the result of
* {@link Cell#getCachedFormulaResultType()}. Otherwise this returns the
* result of {@link Cell#getCellType()}.
*
* @param cell The cell.
*
* @return The ultimate type of this cell.
*/
public static CellType ultimateType(Cell cell) {
CellType type = cell.getCellType();
if (type == CellType.FORMULA)
return cell.getCachedFormulaResultType();
else
return type;
}
代码示例来源:origin: stackoverflow.com
public static boolean isRowEmpty(Row row) {
for (int c = row.getFirstCellNum(); c < row.getLastCellNum(); c++) {
Cell cell = row.getCell(c);
if (cell != null && cell.getCellType() != Cell.CELL_TYPE_BLANK)
return false;
}
return true;
}
代码示例来源:origin: stackoverflow.com
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;
}
}
}
代码示例来源:origin: org.apache.poi/poi
protected static void evaluateAllFormulaCells(Workbook wb, FormulaEvaluator evaluator) {
for(int i=0; i<wb.getNumberOfSheets(); i++) {
Sheet sheet = wb.getSheetAt(i);
for(Row r : sheet) {
for (Cell c : r) {
if (c.getCellType() == CellType.FORMULA) {
evaluator.evaluateFormulaCell(c);
}
}
}
}
}
代码示例来源: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: pentaho/pentaho-kettle
public KCellType getType() {
int type = cell.getCellType();
if ( type == Cell.CELL_TYPE_BOOLEAN ) {
return KCellType.BOOLEAN;
代码示例来源:origin: org.apache.poi/poi
/**
* If cell contains formula, it evaluates the formula,
* and saves the result of the formula. The cell
* remains as a formula cell.
* Else if cell does not contain formula, this method leaves
* the cell unchanged.
* Note that the type of the formula result is returned,
* so you know what kind of value is also stored with
* the formula.
* <pre>
* CellType evaluatedCellType = evaluator.evaluateFormulaCell(cell);
* </pre>
* Be aware that your cell will hold both the formula,
* and the result. If you want the cell replaced with
* the result of the formula, use {@link #evaluate(org.apache.poi.ss.usermodel.Cell)} }
* @param cell The cell to evaluate
* @return The type of the formula result (the cell's type remains as CellType.FORMULA however)
* If cell is not a formula cell, returns {@link CellType#_NONE} rather than throwing an exception.
*/
@Override
public CellType evaluateFormulaCell(Cell cell) {
if (cell == null || cell.getCellType() != CellType.FORMULA) {
return CellType._NONE;
}
CellValue cv = evaluateFormulaCellValue(cell);
// cell remains a formula cell, but the cached value is changed
setCellValue(cell, cv);
return cv.getCellType();
}
代码示例来源:origin: org.apache.poi/poi
return null;
if (cell.getCellType() == CellType.FORMULA) {
CellValue cv = evaluateFormulaCellValue(cell);
代码示例来源:origin: org.apache.poi/poi
switch (cell.getCellType()) {
case BOOLEAN:
return CellValue.valueOf(cell.getBooleanCellValue());
return null;
default:
throw new IllegalStateException("Bad cell type (" + cell.getCellType() + ")");
代码示例来源:origin: org.apache.poi/poi
private void copyRange(CellRangeAddress sourceRange, int deltaX, int deltaY, Sheet sourceClone) { //NOSONAR, it's a bit complex but monolith method, does not make much sense to divide it
if(deltaX != 0)
horizontalFormulaShifter = FormulaShifter.createForColumnCopy(sourceSheet.getWorkbook().getSheetIndex(sourceSheet),
sourceSheet.getSheetName(), sourceRange.getFirstColumn(), sourceRange.getLastColumn(), deltaX, sourceSheet.getWorkbook().getSpreadsheetVersion());
if(deltaY != 0)
verticalFormulaShifter = FormulaShifter.createForRowCopy(sourceSheet.getWorkbook().getSheetIndex(sourceSheet),
sourceSheet.getSheetName(), sourceRange.getFirstRow(), sourceRange.getLastRow(), deltaY, sourceSheet.getWorkbook().getSpreadsheetVersion());
for(int rowNo = sourceRange.getFirstRow(); rowNo <= sourceRange.getLastRow(); rowNo++) {
Row sourceRow = sourceClone.getRow(rowNo); // copy from source copy, original source might be overridden in process!
for (int columnIndex = sourceRange.getFirstColumn(); columnIndex <= sourceRange.getLastColumn(); columnIndex++) {
Cell sourceCell = sourceRow.getCell(columnIndex);
if(sourceCell == null)
continue;
Row destRow = destSheet.getRow(rowNo + deltaY);
if(destRow == null)
destRow = destSheet.createRow(rowNo + deltaY);
Cell newCell = destRow.getCell(columnIndex + deltaX);
if(newCell != null)
newCell.setCellType(sourceCell.getCellType());
else newCell = destRow.createCell(columnIndex + deltaX, sourceCell.getCellType());
cloneCellContent(sourceCell, newCell, null);
if(newCell.getCellType() == CellType.FORMULA)
adjustCellReferencesInsideFormula(newCell, destSheet, deltaX, deltaY);
}
}
}
代码示例来源:origin: org.apache.poi/poi
private ValueAndFormat getCellValue(Cell cell) {
if (cell != null) {
final String format = cell.getCellStyle().getDataFormatString();
CellType type = cell.getCellType();
if (type == CellType.FORMULA) {
type = cell.getCachedFormulaResultType();
}
switch (type) {
case NUMERIC:
return new ValueAndFormat(Double.valueOf(cell.getNumericCellValue()), format, decimalTextFormat);
case STRING:
case BOOLEAN:
return new ValueAndFormat(cell.getStringCellValue(), format);
default:
break;
}
}
return new ValueAndFormat("", "");
}
/**
代码示例来源:origin: org.apache.poi/poi-ooxml
private void handleNonStringCell(StringBuilder text, Cell cell, DataFormatter formatter) {
CellType type = cell.getCellType();
if (type == CellType.FORMULA) {
type = cell.getCachedFormulaResultType();
}
if (type == CellType.NUMERIC) {
CellStyle cs = cell.getCellStyle();
if (cs != null && cs.getDataFormatString() != null) {
String contents = formatter.formatRawCellContents(
cell.getNumericCellValue(), cs.getDataFormat(), cs.getDataFormatString());
checkMaxTextSize(text, contents);
text.append(contents);
return;
}
}
// No supported styling applies to this cell
String contents = ((XSSFCell)cell).getRawValue();
if (contents != null) {
checkMaxTextSize(text, contents);
text.append(contents);
}
}
代码示例来源:origin: org.apache.poi/poi-ooxml
for (Row row : sh) {
for (Cell cell : row) {
if (cell.getCellType() == CellType.FORMULA) {
updateFormula((XSSFCell) cell, oldName, newName);
代码示例来源:origin: pentaho/pentaho-kettle
void recalculateAllWorkbookFormulas() {
if ( data.wb instanceof XSSFWorkbook ) {
// XLSX needs full reevaluation
FormulaEvaluator evaluator = data.wb.getCreationHelper().createFormulaEvaluator();
for ( int sheetNum = 0; sheetNum < data.wb.getNumberOfSheets(); sheetNum++ ) {
Sheet sheet = data.wb.getSheetAt( sheetNum );
for ( Row r : sheet ) {
for ( Cell c : r ) {
if ( c.getCellType() == Cell.CELL_TYPE_FORMULA ) {
evaluator.evaluateFormulaCell( c );
}
}
}
}
} else if ( data.wb instanceof HSSFWorkbook ) {
// XLS supports a "dirty" flag to have excel recalculate everything when a sheet is opened
for ( int sheetNum = 0; sheetNum < data.wb.getNumberOfSheets(); sheetNum++ ) {
HSSFSheet sheet = ( (HSSFWorkbook) data.wb ).getSheetAt( sheetNum );
sheet.setForceFormulaRecalculation( true );
}
} else {
String forceRecalc = getVariable( STREAMER_FORCE_RECALC_PROP_NAME, "N" );
if ( "Y".equals( forceRecalc ) ) {
data.wb.setForceFormulaRecalculation( true );
}
}
}
代码示例来源:origin: org.apache.poi/poi
switch(srcCell.getCellType()) {
case STRING:
destCell.setCellValue(srcCell.getStringCellValue());
代码示例来源:origin: org.apache.poi/poi-ooxml
if (c.getCellType() == CellType.FORMULA) {
eval.evaluateFormulaCell(c);
代码示例来源:origin: org.apache.poi/poi
CellType cellType = cell.getCellType();
if (cellType == CellType.FORMULA) {
if (evaluator == null) {
内容来源于网络,如有侵权,请联系作者删除!