List of usage examples for org.apache.poi.ss.usermodel Cell getBooleanCellValue
boolean getBooleanCellValue();
From source file:org.lisapark.octopus.util.json.JsonUtils.java
License:Open Source License
/** * /* w w w .j a va 2 s. com*/ * @param row * @param cells * @throws JSONException */ private JSONArray jsonFromRow(Row row) throws JSONException { JSONArray cells = new JSONArray(); for (Iterator<Cell> cellsIT = row.cellIterator(); cellsIT.hasNext();) { Cell cell = cellsIT.next(); if (cell.getCellType() == Cell.CELL_TYPE_STRING || cell.getCellType() == Cell.CELL_TYPE_BLANK) { cells.put(cell.getStringCellValue()); } else if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) { cells.put(cell.getNumericCellValue()); } else if (cell.getCellType() == Cell.CELL_TYPE_BOOLEAN) { cells.put(cell.getBooleanCellValue()); } else if (cell.getCellType() == Cell.CELL_TYPE_ERROR) { cells.put(cell.getErrorCellValue()); } else { cells.put("N/A"); } } return cells; }
From source file:org.lisapark.octopus.util.json.JsonUtils.java
License:Open Source License
private String jsonFromRowAsString(Row row) throws JSONException { StringBuilder cells = new StringBuilder(); Boolean first = Boolean.TRUE; Boolean dirty = Boolean.FALSE; // cells.append("["); int i = 0;//from w w w. j a v a 2 s.co m for (Iterator<Cell> cellsIT = row.cellIterator(); cellsIT.hasNext();) { if (dataFieldNames().size() <= i) break; Cell cell = cellsIT.next(); if (cell.getCellType() == Cell.CELL_TYPE_STRING) { if (first) { cells.append(key(dataFieldNames().get(i))).append(quotes(cell.getStringCellValue())); first = Boolean.FALSE; } else { cells.append(",").append(key(dataFieldNames().get(i))) .append(quotes(cell.getStringCellValue())); } dirty = Boolean.TRUE; } else if (cell.getCellType() == Cell.CELL_TYPE_BLANK) { if (first) { cells.append(key(dataFieldNames().get(i))).append(quotes(cell.getStringCellValue())); first = Boolean.FALSE; } else { cells.append(",").append(key(dataFieldNames().get(i))) .append(quotes(cell.getStringCellValue())); } } else if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) { if (first) { cells.append(key(dataFieldNames().get(i))).append(cell.getNumericCellValue()); first = Boolean.FALSE; } else { cells.append(",").append(key(dataFieldNames().get(i))).append(cell.getNumericCellValue()); } dirty = Boolean.TRUE; } else if (cell.getCellType() == Cell.CELL_TYPE_BOOLEAN) { if (first) { cells.append(key(dataFieldNames().get(i))).append(cell.getBooleanCellValue()); first = Boolean.FALSE; } else { cells.append(",").append(key(dataFieldNames().get(i))).append(cell.getBooleanCellValue()); } dirty = Boolean.TRUE; } else if (cell.getCellType() == Cell.CELL_TYPE_ERROR) { if (first) { cells.append(key(dataFieldNames().get(i))).append(cell.getErrorCellValue()); first = Boolean.FALSE; } else { cells.append(",").append(key(dataFieldNames().get(i))).append(cell.getErrorCellValue()); } dirty = Boolean.TRUE; } else { if (first) { cells.append(key(dataFieldNames().get(i))).append("N/A"); first = Boolean.FALSE; } else { cells.append(",").append(key(dataFieldNames().get(i))).append("N/A"); } dirty = Boolean.TRUE; } i++; } if (dirty) { return "{" + cells.append("}").toString(); } else { return ""; } }
From source file:org.lisapark.octopus.util.xml.XmlConverterUtils.java
License:Open Source License
/** * /*from ww w .ja v a2 s . com*/ * @param row * @return * @throws JSONException */ private static String tagAttributesAsString(Row row) throws JSONException { StringBuilder cells = new StringBuilder(); Boolean dirty = Boolean.FALSE; int i = 0; for (Iterator<Cell> cellsIT = row.cellIterator(); cellsIT.hasNext();) { if (dataFieldNames.size() <= i) { break; } Cell cell = cellsIT.next(); if (cell.getCellType() == Cell.CELL_TYPE_STRING) { cells.append(attribute(dataFieldNames.get(i), cell.getStringCellValue())); dirty = Boolean.TRUE; } else if (cell.getCellType() == Cell.CELL_TYPE_BLANK) { // cells.append(attribute(dataFieldNames.get(i), cell.getStringCellValue())); } else if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) { cells.append(attribute(dataFieldNames.get(i), cell.getNumericCellValue())); dirty = Boolean.TRUE; } else if (cell.getCellType() == Cell.CELL_TYPE_BOOLEAN) { cells.append(attribute(dataFieldNames.get(i), cell.getBooleanCellValue())); dirty = Boolean.TRUE; } else if (cell.getCellType() == Cell.CELL_TYPE_ERROR) { cells.append(attribute(dataFieldNames.get(i), cell.getErrorCellValue())); dirty = Boolean.TRUE; } else { cells.append(attribute(dataFieldNames.get(i), "N/A")); dirty = Boolean.TRUE; } i++; } if (dirty) { return cells.toString(); } else { return ""; } }
From source file:org.lisapark.octopus.util.xml.XmlConverterUtils.java
License:Open Source License
private static String buidNodeAsString(Cell cell, int i, int j) { StringBuilder cellStringBuilder = new StringBuilder(); if (cell.getCellType() == Cell.CELL_TYPE_STRING) { String string;//from w w w . j a v a2 s. c o m if (i == 0 && cell.getCellStyle().getIndention() == 2 && treeNodeNames.get(1).equalsIgnoreCase(SHIFT)) { string = extractDateAndShiftAsNodes(cell.getStringCellValue()); if (string != null) { cellStringBuilder.append(string); } else { cellStringBuilder.append(node(dataFieldNames.get(j), cell.getStringCellValue())); } } else { cellStringBuilder.append(node(dataFieldNames.get(j), cell.getStringCellValue())); } } else if (cell.getCellType() == Cell.CELL_TYPE_BLANK) { // cells.append(attribute(dataFieldNames.get(i), cell.getStringCellValue())); } else if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) { cellStringBuilder.append(node(dataFieldNames.get(j), cell.getNumericCellValue())); } else if (cell.getCellType() == Cell.CELL_TYPE_BOOLEAN) { cellStringBuilder.append(node(dataFieldNames.get(j), cell.getBooleanCellValue())); } else if (cell.getCellType() == Cell.CELL_TYPE_ERROR) { cellStringBuilder.append(node(dataFieldNames.get(j), cell.getErrorCellValue())); } else { cellStringBuilder.append(node(dataFieldNames.get(j), "N/A")); } return cellStringBuilder.toString(); }
From source file:org.meveo.service.catalog.impl.PricePlanMatrixService.java
License:Open Source License
private String getCellAsString(Cell cell) { switch (cell.getCellType()) { case Cell.CELL_TYPE_BOOLEAN: return cell.getBooleanCellValue() + ""; case Cell.CELL_TYPE_ERROR: case Cell.CELL_TYPE_BLANK: case Cell.CELL_TYPE_FORMULA: return null; case Cell.CELL_TYPE_NUMERIC: return "" + cell.getNumericCellValue(); default://from w ww .j a v a 2 s . c o m return cell.getStringCellValue(); } }
From source file:org.myorg.insertar.insertarSabanaTopComponent.java
public void procesaDatosEntrada(List sheetData) { ////from w w w. j a v a 2 s.c o m // Iterates the data and print it out to the console. // int cnt = 0; int fProblema = 0; int nTipos = 0; SimpleDateFormat formatDateJava = new SimpleDateFormat("dd-MM-yyyy"); HSSFRichTextString richTextString; // ........................................................................................... for (int i = 0; i < sheetData.size(); i++) { List list = (List) sheetData.get(i); System.out.println(i + " -> Tenemos Exel con " + list.size() + " columnas"); // ........................................................................................... if (cnt == 0) { // CARGAMOS LOS NOMBRES DE LOS CAMPOS for (int j = 0; j < list.size(); j++) { Cell cell = (Cell) list.get(j); // ............................................................ System.out.println("Tipo Nombre =" + cell.getCellType()); if (cell.getCellType() == Cell.CELL_TYPE_STRING) { richTextString = (HSSFRichTextString) cell.getRichStringCellValue(); this.nombres[j] = richTextString.getString(); System.out.println("Cargando Nombre =" + this.nombres[j]); } } this.nColumnas = list.size(); System.out.println("Numero de campos=" + this.nColumnas); } // ........................................................................................... if (cnt == 1) { // CARGAMOS LOS TIPOS DE LOS CAMPOS nTipos = list.size(); for (int j = 0; j < list.size(); j++) { Cell cell = (Cell) list.get(j); if (cell.getCellType() == Cell.CELL_TYPE_STRING) { richTextString = (HSSFRichTextString) cell.getRichStringCellValue(); this.tipos[j] = richTextString.getString(); } if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) { this.tipos[j] = Double.toString(cell.getNumericCellValue()); System.out.println("Cargo this.tipos[" + j + "] = " + this.tipos[j]); } } } // ........................................................................................... if (cnt > 1) { // CARGAMOS LOS DATOS System.out.println("------------CARGAMOS LOS DATOS -----------"); if (nTipos != list.size()) { this.sLogTxt += "AVISO: FILA DATOS(" + (cnt - 2) + ") -> HAY UN PROBLEMA :EL NMERO DE CAMPOS DEFINIDOS Y EL QUE CONTIENE LA L?NEA DE DATOS NO COINCIDE (" + nTipos + "!=" + list.size() + ") \n"; // fProblema = 2 ; } if (fProblema != 2) { for (int j = 0; j < list.size(); j++) { Cell cell = (Cell) list.get(j); this.tablaDatos[cnt - 2][j] = ""; // ............................................................ if (this.tipos[j].equals("4.0")) { // es un tipo fecha SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); try { this.tablaDatos[cnt - 2][j] = String.valueOf(sdf.format(cell.getDateCellValue())); } catch (IllegalStateException e) { this.sLogTxt += "AVISO: FILA DATOS(" + (cnt - 2) + ") -> HAY UN PROBLEMA EL TIPO FECHA EN EL CAMPO: " + this.nombres[j] + "\n"; fProblema = 1; } } else { // ............................................................ if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) { try { this.tablaDatos[cnt - 2][j] = Double.toString(cell.getNumericCellValue()); } catch (IllegalStateException e) { this.sLogTxt += "AVISO: FILA DATOS(" + (cnt - 2) + ") -> HAY UN PROBLEMA EL TIPO DE DATO NUMERICO EN EL CAMPO: " + this.nombres[j] + "\n"; fProblema = 1; } } else if (cell.getCellType() == Cell.CELL_TYPE_STRING) { // ............................................................ try { richTextString = (HSSFRichTextString) cell.getRichStringCellValue(); this.tablaDatos[cnt - 2][j] = richTextString.getString(); } catch (IllegalStateException e) { this.sLogTxt += "AVISO: FILA DATOS(" + (cnt - 2) + ") ->HAY UN PROBLEMA EL TIPO DE DATO TEXTO EN EL CAMPO: " + this.nombres[j] + "\n"; fProblema = 1; } } else if (cell.getCellType() == Cell.CELL_TYPE_BOOLEAN) { // ............................................................ try { this.tablaDatos[cnt - 2][j] = Boolean.toString(cell.getBooleanCellValue()); } catch (IllegalStateException e) { this.sLogTxt += "AVISO: FILA DATOS(" + (cnt - 2) + ") ->HAY UN PROBLEMA EL TIPO DE DATO BOOLEANO EN EL CAMPO: " + this.nombres[j] + "\n"; fProblema = 1; } } else if (cell.getCellType() == Cell.CELL_TYPE_BLANK) { // ............................................................ this.tablaDatos[cnt - 2][j] = ""; } } } // ........................................................................................... } cnt++; } else { // Nos saltamos el procesamiento de esta lnea y seguimos contando. cnt++; fProblema = 0; } } // ........................................................................................... this.nDatos = cnt; System.out.println("----------- HE CARGADO " + this.nDatos + " REGISTROS ------------"); this.sLogTxt += "----------- HE CARGADO " + this.nDatos + " REGISTROS ------------" + "\n"; logAcciones.setText(this.sLogTxt); if (fProblema == 0) { JOptionPane.showMessageDialog(null, "\nHE CARGADO:" + this.nDatos + " REGISTROS", "INFORMACIN", JOptionPane.WARNING_MESSAGE); } else { JOptionPane.showMessageDialog(null, "\nSE HAN DETECTADO PROBLEMAS, SE CANCELA LA CARGA DE ARCHIVO EXEL", "AVISO", JOptionPane.WARNING_MESSAGE); } }
From source file:org.netxilia.impexp.impl.ExcelImportService.java
License:Open Source License
private ICellCommand copyCell(Cell poiCell, CellReference cellReference, HSSFPalette palette, NetxiliaStyleResolver styleResolver) throws FormulaParsingException { CellStyle poiStyle = poiCell.getCellStyle(); Styles styles = PoiUtils.poiStyle2Netxilia(poiStyle, poiCell.getSheet().getWorkbook().getFontAt(poiStyle.getFontIndex()), palette, styleResolver); IGenericValue value = null;// w w w . j av a2 s . com Formula formula = null; // log.info("CELL TYPE:" + cellReference + " type:" + poiCell.getCellType() + " " // + (poiCell.getCellType() == Cell.CELL_TYPE_FORMULA ? poiCell.getCellFormula() : "no")); switch (poiCell.getCellType()) { // TODO translate errors case Cell.CELL_TYPE_STRING: value = new StringValue(poiCell.getStringCellValue()); break; case Cell.CELL_TYPE_NUMERIC: if (DateUtil.isCellDateFormatted(poiCell)) { DateTime dt = new DateTime(poiCell.getDateCellValue()); // TODO decide whether is date or time if (dt.isBefore(EXCEL_START)) { value = new DateValue(dt.toLocalTime()); } else if (dt.getMillisOfDay() == 0) { value = new DateValue(dt.toLocalDate()); } else { value = new DateValue(dt.toLocalDateTime()); } } else { value = new NumberValue(poiCell.getNumericCellValue()); } break; case Cell.CELL_TYPE_BOOLEAN: value = new BooleanValue(poiCell.getBooleanCellValue()); break; case Cell.CELL_TYPE_FORMULA: if (poiCell.getCellFormula() != null) { formula = formulaParser.parseFormula(new Formula("=" + poiCell.getCellFormula())); } break; } if ((styles == null || styles.getItems().isEmpty()) && formula == null && (value == null || value.equals(GenericValueUtils.EMTPY_STRING))) { return null; } return CellCommands.cell(new AreaReference(cellReference), value, formula, styles); }
From source file:org.nuclos.server.common.ooxml.ExcelReader.java
License:Open Source License
private static Object getCellValue(Cell cell, int cellType) { switch (cellType) { case Cell.CELL_TYPE_BLANK: return null; case Cell.CELL_TYPE_BOOLEAN: return cell.getBooleanCellValue(); case Cell.CELL_TYPE_NUMERIC: if (DateUtil.isCellDateFormatted(cell)) { return cell.getDateCellValue(); } else {/* w w w. j a va 2 s. c om*/ return cell.getNumericCellValue(); } case Cell.CELL_TYPE_STRING: return cell.getStringCellValue(); case Cell.CELL_TYPE_ERROR: return FormulaError.forInt(cell.getErrorCellValue()).getString(); case Cell.CELL_TYPE_FORMULA: return cell.getCellFormula(); default: throw new IllegalArgumentException("Unknown POI cell type " + cellType); } }
From source file:org.obiba.onyx.core.io.support.ExcelReaderSupport.java
License:Open Source License
public static Boolean getBooleanValue(HSSFFormulaEvaluator evaluator, Cell cell) { Boolean rvalue = false;//w w w . j a v a2 s .c o m if (cell.getCellType() == Cell.CELL_TYPE_FORMULA) { evaluator.evaluate(cell); CellValue cellValue = evaluator.evaluate(cell); switch (cellValue.getCellType()) { case Cell.CELL_TYPE_BOOLEAN: rvalue = cellValue.getBooleanValue(); break; case Cell.CELL_TYPE_STRING: rvalue = Boolean.parseBoolean(cellValue.getStringValue()); break; } } else { switch (cell.getCellType()) { case Cell.CELL_TYPE_BOOLEAN: rvalue = cell.getBooleanCellValue(); break; case Cell.CELL_TYPE_STRING: rvalue = Boolean.parseBoolean(cell.getRichStringCellValue().getString()); break; } } if (rvalue == null) { throw new IllegalArgumentException("Unexpected cell type"); } return rvalue; }
From source file:org.opencrx.kernel.portal.wizard.ImportAccountsFromXlsController.java
License:BSD License
/** * Read account record.//from w ww .ja va2s .c o m * * @param row * @param nRow * @param maxCell * @param recordDefinition * @param record * @return * @throws ServiceException */ public void readAccountRecord(Row row, int nRow, int maxCell, AccountRecord record, Writer importReport, List<String> errors) throws ServiceException, IOException { importReport.append("<tr class=\"gridTableRowFull\">"); importReport.append("<td>" + DECIMAL_FORMAT_4.format(nRow) + "</td>"); AccountRecordDefinition recordDefinition = record.getRecordDefinition(); Iterator<Cell> cells = row.cellIterator(); int idxCell = 0; while (cells.hasNext()) { Cell cell = (Cell) cells.next(); idxCell = cell.getColumnIndex(); try { if (cell.getCellType() == Cell.CELL_TYPE_STRING) { String cellValue = cell.getStringCellValue().trim(); record.setFieldValue(idxCell, cellValue); if (idxCell == recordDefinition.getIdxDtype()) { if (AccountType.Group.name().compareToIgnoreCase(cellValue) == 0) { record.setTypeExplicitlySet(true); record.setAccountType(AccountType.Group); record.appendImportStatus(idxCell, AccountRecord.ImportStatusElement.ATTR_CLASS, " ok"); } else if (AccountType.LegalEntity.name().compareToIgnoreCase(cellValue) == 0) { record.setTypeExplicitlySet(true); record.setAccountType(AccountType.LegalEntity); record.appendImportStatus(idxCell, AccountRecord.ImportStatusElement.ATTR_CLASS, " ok"); } else if (AccountType.UnspecifiedAccount.name().compareToIgnoreCase(cellValue) == 0) { record.setTypeExplicitlySet(true); record.setAccountType(AccountType.UnspecifiedAccount); record.appendImportStatus(idxCell, AccountRecord.ImportStatusElement.ATTR_CLASS, " ok"); } else if (AccountType.Contact.name().compareToIgnoreCase(cellValue) == 0) { record.setTypeExplicitlySet(true); record.setAccountType(AccountType.Contact); record.appendImportStatus(idxCell, AccountRecord.ImportStatusElement.ATTR_CLASS, " ok"); } } else if (idxCell == recordDefinition.getIdxExtString0()) { record.setExtString0(cellValue); } else if (idxCell == recordDefinition.getIdxFirstName()) { record.setFirstName(cellValue); } else if (idxCell == recordDefinition.getIdxLastName()) { record.setLastName(cellValue); } else if (idxCell == recordDefinition.getIdxAliasName()) { record.setAliasName(cellValue); } else if (idxCell == recordDefinition.getIdxEMailAddress()) { record.setEmailAddress(cellValue); } else if (idxCell == recordDefinition.getIdxCompany()) { record.setCompany(cellValue); } else if (idxCell == recordDefinition.getIdxXri()) { record.setXriExplicitlySet(true); record.setXri(cellValue); } record.appendImportStatus(idxCell, AccountRecord.ImportStatusElement.CONTENT, (cellValue != null ? (cellValue.replace("\r\n", EOL_HTML)).replace("\n", EOL_HTML) : "")); } else if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) { BigDecimal cellValue = new BigDecimal(cell.getNumericCellValue()); if (idxCell == recordDefinition.getIdxExtString0()) { record.setExtString0(cellValue.toString()); record.setFieldValue(idxCell, record.getExtString0()); } else { record.setFieldValue(idxCell, cellValue); } record.appendImportStatus(idxCell, AccountRecord.ImportStatusElement.CONTENT, cellValue.toString()); } else if (cell.getCellType() == Cell.CELL_TYPE_BOOLEAN) { boolean cellValue = cell.getBooleanCellValue(); record.setFieldValue(idxCell, cellValue); record.appendImportStatus(idxCell, AccountRecord.ImportStatusElement.CONTENT, (cellValue ? "TRUE" : "FALSE")); } else if (cell.getCellType() == Cell.CELL_TYPE_BLANK) { record.appendImportStatus(idxCell, AccountRecord.ImportStatusElement.ATTR_CLASS, " empty"); record.appendImportStatus(idxCell, AccountRecord.ImportStatusElement.CONTENT, " "); } else { record.appendImportStatus(idxCell, AccountRecord.ImportStatusElement.ATTR_CLASS, " err"); record.appendImportStatus(idxCell, AccountRecord.ImportStatusElement.CONTENT, "r" + DECIMAL_FORMAT_4.format(nRow) + ":c" + DECIMAL_FORMAT_4.format(idxCell) + ": cell type '" + cell.getCellType() + "' not supported<br>"); } } catch (Exception e) { ServiceException e0 = new ServiceException(e); e0.log(); errors.add(e0.getMessage()); record.appendImportStatus(idxCell, AccountRecord.ImportStatusElement.ATTR_CLASS, " err"); record.appendImportStatus(idxCell, AccountRecord.ImportStatusElement.CONTENT, "r" + DECIMAL_FORMAT_4.format(nRow) + ":c" + DECIMAL_FORMAT_4.format(idxCell) + ": Unknown ERROR. See log.<br>"); } } }