List of usage examples for org.apache.poi.ss.usermodel Cell getBooleanCellValue
boolean getBooleanCellValue();
From source file:org.squashtest.tm.service.internal.batchimport.excel.LiberalBooleanCellCoercer.java
License:Open Source License
/** * @see org.squashtest.tm.service.internal.batchimport.excel.TypeBasedCellValueCoercer#coerceBooleanCell(org.apache.poi.ss.usermodel.Cell) */// w ww. j ava2 s . c om @Override protected Boolean coerceBooleanCell(Cell cell) { return cell.getBooleanCellValue(); }
From source file:org.suren.autotest.web.framework.data.ExcelDataSource.java
License:Apache License
/** * ??/* w ww .j a va 2 s . c o m*/ * @param dataCell * @return ???null */ private String getStrFromCell(Cell dataCell) { int cellType = dataCell.getCellType(); switch (cellType) { case Cell.CELL_TYPE_STRING: return dataCell.getStringCellValue(); case Cell.CELL_TYPE_BOOLEAN: return String.valueOf(dataCell.getBooleanCellValue()); case Cell.CELL_TYPE_NUMERIC: return String.valueOf(dataCell.getNumericCellValue()); default: return null; } }
From source file:org.sysmodb.CellInfo.java
License:BSD License
private void readCellValueAndType(CellType cellType, Cell cell) { switch (cellType) { case BLANK:/*from ww w . j a va2s . c o m*/ value = ""; type = "blank"; break; case BOOLEAN: value = String.valueOf(cell.getBooleanCellValue()); type = "boolean"; break; case NUMERIC: if (DateUtil.isCellDateFormatted(cell)) { type = "datetime"; Date dateCellValue = cell.getDateCellValue(); value = dateFormatter.format(dateCellValue); } else { double numericValue = cell.getNumericCellValue(); int intValue = (int) numericValue; if (intValue == numericValue) { value = String.valueOf(intValue); } else { value = String.valueOf(numericValue); } type = "numeric"; } break; case STRING: value = cell.getStringCellValue(); type = "string"; break; case FORMULA: try { formula = cell.getCellFormula(); } catch (FormulaParseException e) { } CellType resultCellType = cell.getCachedFormulaResultTypeEnum(); readCellValueAndType(resultCellType, cell); break; default: value = ""; type = "none"; break; } }
From source file:org.talend.dataprep.schema.xls.XlsUtils.java
License:Open Source License
/** * * @param cell/*from w w w .ja va 2 s .c o m*/ * @param formulaEvaluator * @return return the cell value as String (if needed evaluate the existing formula) */ public static String getCellValueAsString(Cell cell, FormulaEvaluator formulaEvaluator) { if (cell == null) { return StringUtils.EMPTY; } switch (cell.getCellType()) { case Cell.CELL_TYPE_BLANK: return ""; case Cell.CELL_TYPE_BOOLEAN: return cell.getBooleanCellValue() ? Boolean.TRUE.toString() : Boolean.FALSE.toString(); case Cell.CELL_TYPE_ERROR: return "Cell Error type"; case Cell.CELL_TYPE_FORMULA: try { return getCellValueAsString(cell, formulaEvaluator.evaluate(cell)); } catch (Exception e) { // log error message and the formula LOGGER.warn("Unable to evaluate cell (line: {}, col: {}) with formula '{}': {}", cell.getRowIndex(), cell.getColumnIndex(), cell.getCellFormula(), e.getMessage(), e); return StringUtils.EMPTY; } case Cell.CELL_TYPE_NUMERIC: return getNumericValue(cell, null, false); case Cell.CELL_TYPE_STRING: return StringUtils.trim(cell.getStringCellValue()); default: return "Unknown Cell Type: " + cell.getCellType(); } }
From source file:org.talend.mdm.webapp.browserecords.server.service.UploadService.java
License:Open Source License
protected String getExcelFieldValue(Cell cell) throws Exception { String fieldValue = null;/*from ww w.j a va 2 s.co m*/ int cellType = cell.getCellType(); switch (cellType) { case Cell.CELL_TYPE_NUMERIC: { double tmp = cell.getNumericCellValue(); fieldValue = getStringRepresentation(tmp); break; } case Cell.CELL_TYPE_STRING: { fieldValue = cell.getRichStringCellValue().getString(); break; } case Cell.CELL_TYPE_BOOLEAN: { boolean tmp = cell.getBooleanCellValue(); if (tmp) { fieldValue = "true"; //$NON-NLS-1$ } else { fieldValue = "false";//$NON-NLS-1$ } break; } case Cell.CELL_TYPE_FORMULA: { fieldValue = cell.getCellFormula(); break; } case Cell.CELL_TYPE_ERROR: { break; } case Cell.CELL_TYPE_BLANK: { fieldValue = ""; //$NON-NLS-1$ } default: { } } return fieldValue; }
From source file:org.teiid.translator.excel.ExcelExecution.java
License:Open Source License
/** * @param row// ww w . j a va 2s.c om * @param neededColumns */ List<Object> projectRow(Row row) throws TranslatorException { ArrayList output = new ArrayList(); int id = row.getRowNum() + 1; int i = -1; for (int index : this.visitor.getProjectedColumns()) { i++; // check if the row is ROW_ID if (index == -1) { output.add(id); continue; } Cell cell = row.getCell(index - 1, Row.RETURN_BLANK_AS_NULL); if (cell == null) { output.add(null); continue; } switch (this.evaluator.evaluateInCell(cell).getCellType()) { case Cell.CELL_TYPE_NUMERIC: output.add(convertFromExcelType(cell.getNumericCellValue(), cell, this.expectedColumnTypes[i])); break; case Cell.CELL_TYPE_STRING: output.add(convertFromExcelType(cell.getStringCellValue(), this.expectedColumnTypes[i])); break; case Cell.CELL_TYPE_BOOLEAN: if (this.expectedColumnTypes[i].isAssignableFrom(Boolean.class)) { output.add(Boolean.valueOf(cell.getBooleanCellValue())); } else { throw new TranslatorException(ExcelPlugin.Event.TEIID23001, ExcelPlugin.Util .gs(ExcelPlugin.Event.TEIID23001, this.expectedColumnTypes[i].getName())); } break; default: output.add(null); break; } } return output; }
From source file:org.tiefaces.components.websheet.utility.CellUtility.java
License:MIT License
/** * Gets the cell string value with boolean type. * * @param poiCell/*www. j a v a 2 s .c om*/ * the poi cell * @return the cell string value with boolean type */ private static String getCellStringValueWithBooleanType(final Cell poiCell) { if (poiCell.getBooleanCellValue()) { return "Y"; } else { return "N"; } }
From source file:org.tridas.io.formats.ooxml.OOXMLReader.java
License:Apache License
private String getCellValueAsString(Cell cell) { if (cell.getCellType() == Cell.CELL_TYPE_BLANK) { return null; } else if (cell.getCellType() == Cell.CELL_TYPE_BOOLEAN) { if (cell.getBooleanCellValue() == true) { return "true"; } else {/* ww w . j ava 2 s . co m*/ return "false"; } } else if (cell.getCellType() == Cell.CELL_TYPE_ERROR) { return null; } else if (cell.getCellType() == Cell.CELL_TYPE_FORMULA) { try { return cell.getStringCellValue(); } catch (Exception e) { return null; } } else if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) { return String.valueOf(cell.getNumericCellValue()); } else if (cell.getCellType() == Cell.CELL_TYPE_STRING) { return cell.getStringCellValue(); } return null; }
From source file:org.tsukuba_bunko.lilac.helper.port.impl.ImportDataHelperBase.java
License:Open Source License
private String getCellValue(Cell cell) { switch (cell.getCellType()) { case Cell.CELL_TYPE_BOOLEAN: return String.valueOf(cell.getBooleanCellValue()); case Cell.CELL_TYPE_NUMERIC: return String.valueOf(Math.round(cell.getNumericCellValue())); case Cell.CELL_TYPE_STRING: return cell.getStringCellValue(); }/*w w w .j a v a2 s . c o m*/ return null; }
From source file:org.tuxedoberries.transformo.excel.XLSXDataReader.java
License:Open Source License
private RowData generateData(Row row) { if (row == null) { Logger.Error("Row is null"); return null; }/*w w w . ja v a 2s .c om*/ int total = row.getLastCellNum(); RowData rdata = new RowData(); for (int i = 0; i < total; ++i) { FieldMeta fmeta = _tmeta.GetOrCreateField(i); Cell cell = row.getCell(i); if (cell == null) { continue; } switch (cell.getCellType()) { case Cell.CELL_TYPE_NUMERIC: rdata.addData(fmeta, cell.getNumericCellValue()); break; case Cell.CELL_TYPE_STRING: rdata.addData(fmeta, cell.getStringCellValue()); break; case Cell.CELL_TYPE_BOOLEAN: rdata.addData(fmeta, cell.getBooleanCellValue()); break; case Cell.CELL_TYPE_BLANK: Logger.Warning("Empty Data Field. Expected a [%s]", fmeta.DataType); break; case Cell.CELL_TYPE_FORMULA: Logger.Warning("Data Type is not supported [FORMULA]"); break; case Cell.CELL_TYPE_ERROR: Logger.Error("Error Reading Cell"); break; } } return rdata; }