List of usage examples for org.apache.poi.ss.usermodel Cell getDateCellValue
Date getDateCellValue();
From source file:data.control.dataSheet.java
public ArrayList<Patient> getPatients() { ArrayList<XSSFRow> theRows; ArrayList<Patient> thePatients = new ArrayList(); boolean firstRowSkipped = false; connect();/*from w w w . jav a2 s.c o m*/ theRows = fetchRows(); // looping through the rows Iterator<XSSFRow> rowIterator = theRows.iterator(); while (rowIterator.hasNext()) { // reading the row Row aRow = rowIterator.next(); if (!firstRowSkipped) { firstRowSkipped = true; continue; } Patient aPatient = new Patient(); // loading the cells Iterator<Cell> cellIterator = aRow.cellIterator(); // looping through the cells while (cellIterator.hasNext()) { // reading the cell Cell cell = cellIterator.next(); if (cell != null) { switch (cell.getColumnIndex()) { case 0: // ID aPatient.setID((int) cell.getNumericCellValue()); break; case 1: // Name aPatient.setName(cell.getStringCellValue()); break; case 2: // heart rate case 3: // heart rate case 4: // heart rate case 5: // heart rate case 6: // heart rate //aPatient.addHeartRate(cell.getNumericCellValue()); break; case 7: // tempreature case 8: // tempreature case 9: // tempreature case 10:// tempreature case 11:// tempreature //aPatient.addTempreature(cell.getNumericCellValue()); break; case 12: // blood_type aPatient.setBloodType(cell.getStringCellValue()); break; case 13: // sex aPatient.setSex(cell.getStringCellValue()); break; case 14: // age aPatient.setAge((int) cell.getNumericCellValue()); break; case 15: // date_added aPatient.setDateAdded(cell.getDateCellValue()); break; case 16: // last_updated aPatient.setLastUpdated(cell.getDateCellValue()); break; case 17: // last_alarmed aPatient.setLastAlarm(cell.getDateCellValue()); default: break; } } } // adding patient to the collection if (aPatient.getName() != null) { thePatients.add(aPatient); } //aPatient.printAll(); } //closeConnection(); return thePatients; }
From source file:de.enerko.reports2.engine.CellDefinition.java
License:Apache License
protected CellValue parse_number(Cell in) { CellValue rv = null;/*from w w w. j a v a 2 s. c om*/ try { if (HSSFDateUtil.isCellDateFormatted(in)) { rv = new CellValue("datetime", Report.DATEFORMAT_OUT.format(in.getDateCellValue())); } else { rv = new CellValue("number", Double.toString(in.getNumericCellValue())); } } catch (IllegalStateException e) { // Siehe Dokumentation getNumericCellValue rv = new CellValue("string", in.getStringCellValue()); } return rv; }
From source file:de.fhg.fokus.odp.portal.uploaddata.service.Worker.java
/** * This method handles some dates, parses and adds them as a correct String * to our map.// ww w .j a v a 2s .c o m * * @param map * HashMap which stores the (key,value)-pairs * @param parameter * this is the name of this column * @param cell * @param extrasStringBuilder * intermediate extrasString */ private void handleDate(HashMap<String, String> map, String parameter, Cell cell, StringBuilder extrasStringBuilder) { String val; SimpleDateFormat form = new SimpleDateFormat("yyyy-MM-dd"); val = form.format(cell.getDateCellValue()); if (parameter.startsWith("extras:")) { String[] tmp = parameter.split(":"); parseExtras(extrasStringBuilder, tmp[1], val); } else { map.put(parameter, "\"" + val + "\""); } }
From source file:de.ingrid.iplug.excel.service.SheetsService.java
License:EUPL
/** * Get formatted data.//from ww w . ja v a 2 s . c om * * @param cell * @return Formated date. */ private static String getFormattedDateString(final Cell cell) { final Date date = cell.getDateCellValue(); final SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); final String formatedDate = formatter.format(date); return formatedDate; }
From source file:de.iteratec.iteraplan.businesslogic.exchange.elasticExcel.excelimport.EntityDataImporter.java
License:Open Source License
/** * RuntimePeriod get special handling, because they need two columns for one primitive type. * //w w w.j av a2 s.c om * @param instance * @param featureExpression * @param startCell * @param endCell */ private void importRuntimePeriodExpression(UniversalModelExpression instance, FeatureExpression<?> featureExpression, Cell startCell, Cell endCell) { try { Date startDate = (startCell != null) ? startCell.getDateCellValue() : null; Date endDate = (endCell != null) ? endCell.getDateCellValue() : null; if (startDate == null && endDate == null) { return; } if (startDate != null && endDate != null && startDate.getTime() > endDate.getTime()) { DateFormat df = DateFormat.getDateInstance(DateFormat.MEDIUM, UserContext.getCurrentLocale()); logError("Near cell {0}: RuntimePeriod: from {1} until {2} in instance {3}", ExcelUtils.getFullCellName(startCell), df.format(startDate), df.format(endDate), instance); } else { RuntimePeriod rt = new RuntimePeriod(startDate, endDate); setValue(instance, (PropertyExpression<?>) featureExpression, rt, startCell); } } catch (Exception e) { logError("Near cell {0}: Error importing runtime period in {1}: {2}", ExcelUtils.getFullCellName(startCell), instance, e.getMessage()); } }
From source file:de.iteratec.iteraplan.businesslogic.exchange.elasticExcel.util.ExcelUtils.java
License:Open Source License
/** * get the attribute from the cell. Do basic type conversions. * /* ww w .j ava 2 s . com*/ * @param cell the cell to read * @param convertNumberToDate if true, AND if the cell type is numeric, convert the cell value to Date; use the * numeric value otherwise. * * @return the value from the cell, or null if cell is empty. */ @SuppressWarnings({ "PMD.MissingBreakInSwitch", "boxing" }) public static Object getCellValue(Cell cell, boolean convertNumberToDate) { switch (cell.getCellType()) { case Cell.CELL_TYPE_BLANK: return null; case Cell.CELL_TYPE_BOOLEAN: return cell.getBooleanCellValue(); case Cell.CELL_TYPE_NUMERIC: if (convertNumberToDate) { return cell.getDateCellValue(); } else { return cell.getNumericCellValue(); } case Cell.CELL_TYPE_STRING: return StringUtils.trim(cell.getStringCellValue()); case Cell.CELL_TYPE_ERROR: LOGGER.error("Error in cell {0}: contains Error", ExcelUtils.getFullCellName(cell)); return null; case Cell.CELL_TYPE_FORMULA: return cell.getCellFormula(); default: // impossible. LOGGER.error("Error in cell {0}: contains unknown cell type.", ExcelUtils.getFullCellName(cell)); return null; } }
From source file:de.iteratec.iteraplan.businesslogic.exchange.legacyExcel.importer.ExcelImportUtilities.java
License:Open Source License
public static Date getDate(Cell dateCell, String dateCellCoords, String elementName) { Date date = null;/*from ww w.j a v a2 s . c om*/ if (dateCell != null) { try { date = dateCell.getDateCellValue(); } catch (IllegalStateException ex) { getProcessingLog().info("Cell [{0}] Date not found, assuming null: {1}", dateCellCoords, elementName); LOGGER.info(ex); } catch (NumberFormatException ex) { getProcessingLog().warn("Cell [{0}] Date invalid, assuming null: {1}", dateCellCoords, elementName); LOGGER.warn(ex); } } return date; }
From source file:de.iteratec.iteraplan.businesslogic.exchange.legacyExcel.importer.ExcelImportUtilities.java
License:Open Source License
/** * Returns cell content as Date. A cell being null or empty returns NULL. For Strings an * exception is thrown. Directly using poi's getDateCellValue() on a HSSFCell being NULL would * throw an exception. Cell in row is specified by the headline map and the key. * //from w w w. ja v a 2 s .c o m * @param cell * a cell containing a date * @return a Date * @throws NumberFormatException */ public static Date contentAsDate(Cell cell) { Date date = null; if (!ExcelImportUtilities.isEmpty(cell)) { date = cell.getDateCellValue(); } return date; }
From source file:de.jlo.talendcomp.excel.SpreadsheetInput.java
License:Apache License
private String getStringCellValue(Cell cell, int originalColumnIndex) throws Exception { String value = null;// w ww. j a va 2s. com if (cell != null) { CellType cellType = cell.getCellTypeEnum(); if (cellType == CellType.FORMULA) { try { value = getDataFormatter().formatCellValue(cell, getFormulaEvaluator()); } catch (Exception e) { if (useCachedValuesForFailedEvaluations) { cellType = cell.getCachedFormulaResultTypeEnum(); if (cellType == CellType.STRING) { if (returnURLInsteadOfName) { Hyperlink link = cell.getHyperlink(); if (link != null) { if (concatenateLabelUrl) { String url = link.getAddress(); if (url == null) { url = ""; } String label = link.getLabel(); if (label == null) { label = ""; } value = label + "|" + url; } else { value = link.getAddress(); } } else { value = cell.getStringCellValue(); } } else { value = cell.getStringCellValue(); } } else if (cellType == CellType.NUMERIC) { if (DateUtil.isCellDateFormatted(cell)) { if (defaultDateFormat != null) { Date d = cell.getDateCellValue(); if (d != null) { value = defaultDateFormat.format(d); } } else { value = getDataFormatter().formatCellValue(cell); } } else { if (overrideExcelNumberFormat) { value = getNumberFormat(originalColumnIndex).format(cell.getNumericCellValue()); } else { value = getDataFormatter().formatCellValue(cell); } } } else if (cellType == CellType.BOOLEAN) { value = cell.getBooleanCellValue() ? "true" : "false"; } } else { throw e; } } } else if (cellType == CellType.STRING) { if (returnURLInsteadOfName) { Hyperlink link = cell.getHyperlink(); if (link != null) { if (concatenateLabelUrl) { String url = link.getAddress(); if (url == null) { url = ""; } String label = link.getLabel(); if (label == null) { label = ""; } value = label + "|" + url; } else { value = link.getAddress(); } } else { value = cell.getStringCellValue(); } } else { value = cell.getStringCellValue(); } } else if (cellType == CellType.NUMERIC) { if (DateUtil.isCellDateFormatted(cell)) { value = getDataFormatter().formatCellValue(cell); } else { if (overrideExcelNumberFormat) { value = getNumberFormat(originalColumnIndex).format(cell.getNumericCellValue()); } else { value = getDataFormatter().formatCellValue(cell); } } } else if (cellType == CellType.BOOLEAN) { value = cell.getBooleanCellValue() ? "true" : "false"; } else if (cellType == CellType.BLANK) { value = null; } } return value; }
From source file:de.jlo.talendcomp.excel.SpreadsheetInput.java
License:Apache License
private Date getDateCellValue(Cell cell, String pattern) throws Exception { Date value = null;/*from w w w . j a v a 2 s. c o m*/ if (cell != null) { CellType cellType = cell.getCellTypeEnum(); if (cellType == CellType.FORMULA) { try { String s = getDataFormatter().formatCellValue(cell, getFormulaEvaluator()); return parseDate(s, pattern); } catch (Exception e) { if (useCachedValuesForFailedEvaluations) { cellType = cell.getCachedFormulaResultTypeEnum(); if (cellType == CellType.STRING) { String s = cell.getStringCellValue(); value = parseDate(s, pattern); } else if (cellType == CellType.NUMERIC) { value = cell.getDateCellValue(); } } else { throw e; } } } else if (cellType == CellType.NUMERIC) { if (DateUtil.isCellDateFormatted(cell) && parseDateFromVisibleString == false) { value = cell.getDateCellValue(); } else { String s = getDataFormatter().formatCellValue(cell); value = parseDate(s, pattern); } } else if (cellType == CellType.STRING) { String s = getDataFormatter().formatCellValue(cell); value = parseDate(s, pattern); } } if (returnZeroDateAsNull && GenericDateUtil.isZeroDate(value)) { value = null; } return value; }