/** * @return cell type */ @Override public CellType getCellType() { return _cell.getCellType(); } /**
return getStringCellValue(); default: return "Unknown Cell Type: " + getCellType();
/** * get the cells type (numeric, formula or string) * @since POI 3.15 beta 3 */ @Deprecated @Removal(version = "4.2") @Override public CellType getCellTypeEnum() { return getCellType(); }
/** * Get the hssfcell representing a given column (logical cell) * 0-based. If you ask for a cell that is not defined, then * your supplied policy says what to do * * @param cellnum 0 based column number * @param policy Policy on blank / missing cells * @return representing that column or null if undefined + policy allows. */ @Override public HSSFCell getCell(int cellnum, MissingCellPolicy policy) { HSSFCell cell = retrieveCell(cellnum); switch (policy) { case RETURN_NULL_AND_BLANK: return cell; case RETURN_BLANK_AS_NULL: boolean isBlank = (cell != null && cell.getCellType() == CellType.BLANK); return (isBlank) ? null : cell; case CREATE_NULL_AS_BLANK: return (cell == null) ? createCell(cellnum, CellType.BLANK) : cell; default: throw new IllegalArgumentException("Illegal policy " + policy); } }
switch(cell.getCellType()) { case STRING: text.append(cell.getRichStringCellValue().getString()); throw new RuntimeException("Unexpected cell type (" + cell.getCellType() + ")");
newCell.setCellType(oldCell.getCellType()); switch (oldCell.getCellType()) { case Cell.CELL_TYPE_BLANK: newCell.setCellValue(oldCell.getStringCellValue());
/** * @return cell type */ @Override public CellType getCellType() { return _cell.getCellType(); } /**
public int getCellType() { return _cell.getCellType(); } public int getColumnIndex() {
public int getCellType() { return _cell.getCellType(); } public int getColumnIndex() {
HSSFCell cell = (HSSFCell) cells.next(); int type = cell.getCellType();
for (String headerName : headers.keySet()) { int headerIndex = headers.get(headerName); HSSFCell cell = row.getCell(headerIndex); if (cell != null) { switch (cell.getCellType()) { case HSSFCell.CELL_TYPE_NUMERIC: // handle number continue; // move to next header case HSSFCell.CELL_TYPE_STRING: // handle string continue; // move to next header default: // do nothing } } // handle case where either cell is empty or its type is "not supported" }
/** * get the cells type (numeric, formula or string) * @since POI 3.15 beta 3 */ @Deprecated @Removal(version = "4.2") @Override public CellType getCellTypeEnum() { return getCellType(); }
InputStream myxls = new FileInputStream("workbook.xls"); wb = new HSSFWorkbook(myxls); sheet = wb.getSheetAt(0); // first sheet row = sheet.getRow(0); // third row HSSFCell cell = (HSSFCell) row.getCell((short)1); // fourth cell if (cell.getCellType() == HSSFCell.CELL_TYPE_STRING) { System.out.println("The Cell was a String with value \" " + cell.getStringCellValue()+" \" "); } else if (cell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC) { System.out.println("The cell was a number " + cell.getNumericCellValue()); } else { System.out.println("The cell was nothing we're interested in"); }
boolean hasDataFlag = true; HSSFRow row = sheet.getRow(rowNumber); hasDataFlag = (row != null); HSSFCell cell = null; if (hasDataFlag) cell = row.getCell(cellNumber); hasDataFlag = (cell != null); if (hasDataFlag) hasDataFlag = (cell.getCellType() != Cell.CELL_TYPE_BLANK); if (hasDataFlag) { // process the cell here }
HSSFCell cell = poiFilaActual.getCell(intColActual); if (cell != null) { if (HSSFCell.CELL_TYPE_STRING == cell.getCellType()) { return cell.getRichStringCellValue().toString(); } else if (HSSFCell.CELL_TYPE_BOOLEAN == cell.getCellType()) { return new String( (cell.getBooleanCellValue() == true ? "true" : "false") ); } else if (HSSFCell.CELL_TYPE_BLANK == cell.getCellType()) { return ""; } else if (HSSFCell.CELL_TYPE_NUMERIC == cell.getCellType()) { if(HSSFDateUtil.isCellDateFormatted(cell)){ return ( new SimpleDateFormat("dd/MM/yyyy").format(cell.getDateCellValue()) ); }else{ return new BigDecimal(cell.getNumericCellValue()).toString(); } } }
protected String inlineBandDataToCellString(HSSFCell cell, String templateCellValue, BandData band) { String resultStr = ""; if (cell.getCellType() == HSSFCell.CELL_TYPE_STRING) { if (templateCellValue != null) resultStr = templateCellValue; } else { if (cell.toString() != null) resultStr = cell.toString(); } if (StringUtils.isNotEmpty(resultStr)) return insertBandDataToString(band, resultStr); return ""; }
protected String inlineBandDataToCellString(HSSFCell cell, String templateCellValue, BandData band) { String resultStr = ""; if (cell.getCellType() == HSSFCell.CELL_TYPE_STRING) { if (templateCellValue != null) resultStr = templateCellValue; } else { if (cell.toString() != null) resultStr = cell.toString(); } if (StringUtils.isNotEmpty(resultStr)) return insertBandDataToString(band, resultStr); return ""; }
private Object getCellValue(HSSFCell cell) { if (cell == null) { return null; } if (cell.getCellType() == Cell.CELL_TYPE_FORMULA) { switch (cell.getCachedFormulaResultType()) { case Cell.CELL_TYPE_NUMERIC: return cell.getNumericCellValue(); case Cell.CELL_TYPE_STRING: return cell.getStringCellValue().replaceAll("'", ""); } } return null; }
@Converter public static String[] convertExcelRow(HSSFRow row) { String[] result = new String[row.getLastCellNum()]; for (int i = 0; i < row.getLastCellNum(); i++) { HSSFCell cell = row.getCell(i); if (cell != null) { int type = cell.getCellType(); switch(type) { case HSSFCell.CELL_TYPE_STRING: result[i] = cell.getStringCellValue(); break; case HSSFCell.CELL_TYPE_NUMERIC: result[i] = convertDouble(cell.getNumericCellValue()); break; } } } return result; }
protected void updateFormulas(Area templateArea, Area dependentResultArea) { HSSFSheet templateSheet = getTemplateSheetForRangeName(templateWorkbook, templateArea.getName()); HSSFSheet resultSheet = templateToResultSheetsMapping.get(templateSheet); AreaReference area = dependentResultArea.toAreaReference(); for (CellReference cell : area.getAllReferencedCells()) { HSSFCell resultCell = getCellFromReference(cell, resultSheet); if (resultCell.getCellType() == HSSFCell.CELL_TYPE_FORMULA) { Ptg[] ptgs = HSSFFormulaParser.parse(resultCell.getCellFormula(), resultWorkbook); for (Ptg ptg : ptgs) { if (ptg instanceof AreaPtg) { areaDependencyManager.updateAreaPtg(templateArea, dependentResultArea, (AreaPtg) ptg); } else if (ptg instanceof RefPtg) { areaDependencyManager.updateRefPtg(templateArea, dependentResultArea, (RefPtg) ptg); } } String calculatedFormula = HSSFFormulaParser.toFormulaString(templateWorkbook, ptgs); resultCell.setCellFormula(calculatedFormula); } } }