List of usage examples for org.apache.poi.ss.usermodel Cell getRowIndex
int getRowIndex();
From source file:de.topicmapslab.jexc.utility.XlsxCellUtils.java
License:Apache License
/** * Returns the cell range of the given cell * /*from w w w .j a va 2 s . co m*/ * @param cell * the cell * @return the cell range of merged region the cell is part of or * <code>null</code> */ public static CellRangeAddress getCellRange(Cell cell) { Sheet s = cell.getSheet(); for (int i = 0; i < s.getNumMergedRegions(); i++) { CellRangeAddress a = s.getMergedRegion(i); if (a.isInRange(cell.getRowIndex(), cell.getColumnIndex())) { return a; } } return null; }
From source file:dk.cubing.liveresults.uploader.parser.WcaParser.java
License:Open Source License
/** * @param row// www . j a va 2s . co m * @param i * @return * @throws IllegalStateException */ private int parseResultCell(Row row, int i) throws IllegalStateException { int result = 0; Cell cell = row.getCell(3 + i); if (cell != null && cell.getCellType() != Cell.CELL_TYPE_BLANK) { String cellStr = null; switch (cell.getCellType()) { // result values case Cell.CELL_TYPE_NUMERIC: // seconds if ("0.00".equals(cell.getCellStyle().getDataFormatString())) { result = new Double(cell.getNumericCellValue() * 100).intValue(); // minutes } else if ("M:SS.00".equalsIgnoreCase(cell.getCellStyle().getDataFormatString())) { try { result = resultTimeFormat.formatDateToInt(cell.getDateCellValue()); } catch (ParseException e) { log.error("[{}] " + e.getLocalizedMessage(), e); } // number } else if ("0".equals(cell.getCellStyle().getDataFormatString())) { result = new Double(cell.getNumericCellValue()).intValue(); // unsupported } else { log.warn("[{}] Unsupported cell format: {}. Row/Column ({}, {})", new Object[] { row.getSheet().getSheetName(), cell.getCellStyle().getDataFormatString(), cell.getRowIndex(), cell.getColumnIndex() }); } break; // Penalties case Cell.CELL_TYPE_STRING: cellStr = cell.getStringCellValue(); if (cellStr != null) { if (cellStr.equalsIgnoreCase(Result.Penalty.DNF.toString())) { result = Result.Penalty.DNF.getValue(); } else if (cellStr.equalsIgnoreCase(Result.Penalty.DNS.toString())) { result = Result.Penalty.DNS.getValue(); } } break; // best / worst case Cell.CELL_TYPE_FORMULA: CellValue cellValue = evaluator.evaluate(cell); switch (cellValue.getCellType()) { // calculated value case Cell.CELL_TYPE_NUMERIC: // seconds if ("0.00".equals(cell.getCellStyle().getDataFormatString())) { result = new Double(cellValue.getNumberValue() * 100).intValue(); // minutes } else if ("M:SS.00".equalsIgnoreCase(cell.getCellStyle().getDataFormatString())) { try { result = resultTimeFormat.formatDateToInt(cell.getDateCellValue()); } catch (ParseException e) { log.error("[{}] " + e.getLocalizedMessage(), e); } // number } else if ("0".equals(cell.getCellStyle().getDataFormatString()) || "GENERAL".equals(cell.getCellStyle().getDataFormatString())) { result = new Double(cell.getNumericCellValue()).intValue(); // unsupported } else { log.warn("[{}] Unsupported cell format: {}. Row/Column ({}, {})", new Object[] { row.getSheet().getSheetName(), cell.getCellStyle().getDataFormatString(), cell.getRowIndex(), cell.getColumnIndex() }); } break; // Penalties case Cell.CELL_TYPE_STRING: cellStr = cellValue.getStringValue(); if (cellStr != null) { if (cellStr.equalsIgnoreCase(Result.Penalty.DNF.toString())) { result = Result.Penalty.DNF.getValue(); } else if (cellStr.equalsIgnoreCase(Result.Penalty.DNS.toString())) { result = Result.Penalty.DNS.getValue(); } } break; } break; } } return result; }
From source file:edu.emory.cci.aiw.cvrg.eureka.etl.spreadsheet.XlsxDataProvider.java
License:Open Source License
private void throwException(String sheetName, Cell cell, String problemDescription, Exception cause) throws DataProviderException { String msgTemplate = messages.getString("xlsxDataProvider.error.parsing"); CellReference cellRef = new CellReference(cell.getRowIndex(), cell.getColumnIndex()); String msg = MessageFormat.format(msgTemplate, sheetName, cellRef.formatAsString(), problemDescription); throw new DataProviderException(msg, cause); }
From source file:edu.gatech.pmase.capstone.awesome.impl.database.AbstractDatabaseDriver.java
License:Open Source License
/** * Reads in a List of IDs contained within a Cell. * * @param cell the Cell to read from/* w w w.j a v a 2 s .c o m*/ * * @return a List of ID's contained within the given Cell. */ protected List<Long> getListFromCell(final Cell cell) { List<Long> result = new ArrayList<>(1); if (null != cell && cell.getCellType() != Cell.CELL_TYPE_BLANK) { if (cell.getCellType() == Cell.CELL_TYPE_STRING) { final String[] split = cell.getStringCellValue().replaceAll(" ", "").split(LIST_STRING_SPLIT_REGEX); // check if single value if (null != split && split.length > 0) { result = Arrays.asList(split).stream().map((String str) -> Long.parseLong(str)) .collect(Collectors.toList()); } else { LOGGER.error("Invalid List of values found in DB in cell: [" + cell.getRowIndex() + "," + cell.getColumnIndex() + "]"); } } else if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) { result.add((long) cell.getNumericCellValue()); } } return result; }
From source file:edu.gatech.pmase.capstone.awesome.impl.database.AbstractDatabaseDriver.java
License:Open Source License
/** * Reads in the TerrainEffect list from a given Cell. * * @param cell the cell to read from * @param terrainCodeNum the terrain code of the given column for the Cell. * * @return A List of TerrainEffects specified in the given Cell *//*from w w w.j a v a 2 s . c o m*/ protected List<TerrainEffect> getTerrainEffectsFromCell(final Cell cell, final int terrainCodeNum) { final List<TerrainEffect> effects = new ArrayList<>(); for (final Long terrainId : this.getListFromCell(cell)) { final TerrainEffect effect = TerrainEffect.getEffectByIdAndCode(terrainId.intValue(), terrainCodeNum); if (TerrainEffect.UNKNOWN == effect) { LOGGER.error("Unknown TerrainEffect with id: " + terrainId + " and code: " + terrainCodeNum + " found in DB for cell: [" + cell.getRowIndex() + "," + cell.getColumnIndex() + "]"); } else { effects.add(effect); } } LOGGER.debug("Found " + effects.size() + " Terrian Effect Restrictions with code num: " + terrainCodeNum); return effects; }
From source file:edu.gatech.pmase.capstone.awesome.impl.database.PlatformDatabaseDriver.java
License:Open Source License
/** * Gets the Platform type from the typeCell * * @param typeCell theCell to get the Platform Type from * * @return the Platform Type/*from w ww .j av a 2s . co m*/ */ private static PlatformType getPlatformType(final Cell typeCell) { PlatformType t; if (null != typeCell) { if (typeCell.getCellType() == Cell.CELL_TYPE_STRING) { final String val = typeCell.getStringCellValue(); switch (val) { case "A": t = PlatformType.AIR; break; case "G": t = PlatformType.GROUND; break; case "W": t = PlatformType.WATER; break; default: t = PlatformType.UNKNOWN; } } else { LOGGER.warn("Could not read platform type for cell: [" + typeCell.getRowIndex() + "," + typeCell.getColumnIndex() + "]"); t = PlatformType.UNKNOWN; } } else { LOGGER.warn("Could not read platform type for cell"); t = PlatformType.UNKNOWN; } return t; }
From source file:es.SSII2.manager.ExcelManagerAccount.java
public void readAccountExcel() throws FileNotFoundException, IOException { FileInputStream file;//from w w w . j av a 2 s .c o m file = new FileInputStream(new File(excel)); try (XSSFWorkbook workbook = new XSSFWorkbook(file)) { XSSFSheet sheet = workbook.getSheetAt(0); Iterator<Row> rowIterator = sheet.iterator(); Row row; // Recorremos todas las filas para mostrar el contenido de cada celda while (rowIterator.hasNext()) { row = rowIterator.next(); // Obtenemos el iterator que permite recorres todas las celdas de una fila Iterator<Cell> cellIterator = row.cellIterator(); Cell celda; double val; DecimalFormat df = new DecimalFormat("#"); while (cellIterator.hasNext()) { celda = cellIterator.next(); if (celda.getRowIndex() >= 1 && celda.getColumnIndex() == 8 && celda.getCellType() != 3) { val = celda.getNumericCellValue(); String stringPOI = NumberToTextConverter.toText(val); //anadir la cuenta al arraylist y las posiciones account.addAccount(stringPOI); account.addAccountPos(celda.getRowIndex() + "-" + celda.getColumnIndex()); } } } } }
From source file:es.SSII2.manager.ExcelManagerMail.java
public void readAccountExcel() throws FileNotFoundException, IOException { FileInputStream file;//from w w w. j a v a 2 s. c o m file = new FileInputStream(new File(excel)); try (XSSFWorkbook workbook = new XSSFWorkbook(file)) { XSSFSheet sheet = workbook.getSheetAt(0); Iterator<Row> rowIterator = sheet.iterator(); Row row; // Recorremos todas las filas para mostrar el contenido de cada celda while (rowIterator.hasNext()) { workers = new WorkersID(); row = rowIterator.next(); // Obtenemos el iterator que permite recorres todas las celdas de una fila Iterator<Cell> cellIterator = row.cellIterator(); Cell celda; String celdas; while (cellIterator.hasNext()) { celda = cellIterator.next(); if (celda.getRowIndex() >= 1 && celda.getColumnIndex() == 0 && celda.getCellType() != 3) { celdas = celda.getStringCellValue(); //anadir la cuenta al arraylist y las posiciones workers.setNombre(celdas); } if (celda.getRowIndex() >= 1 && celda.getColumnIndex() == 1 && celda.getCellType() != 3) { celdas = celda.getStringCellValue(); //anadir la cuenta al arraylist y las posiciones workers.setApellido1(celdas); } if (celda.getRowIndex() >= 1 && celda.getColumnIndex() == 2 && celda.getCellType() != 3) { celdas = celda.getStringCellValue(); //anadir la cuenta al arraylist y las posiciones workers.setApellido2(celdas); } if (celda.getRowIndex() >= 1 && celda.getColumnIndex() == 6 && celda.getCellType() != 3) { celdas = celda.getStringCellValue(); //anadir la cuenta al arraylist y las posiciones workers.setEmpresa(celdas); } } //se mete los datos en el arraylist if (workers.getNombre() != null) arrayWorkers.add(workers); } } //System.out.println(arrayWorkers.get(6).getApellido1()); email = new WorkersEmail(arrayWorkers); email.creacionCorreos(); }
From source file:eu.learnpad.ontology.kpi.data.ExcelParser.java
public List<List<String>> getDataTable() throws IOException, InvalidFormatException { List<List<String>> dataTable = new ArrayList<>(); Integer rowNumber = -2;/* www. j a v a2s. co m*/ Workbook wb = WorkbookFactory.create(excelFile); FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator(); for (Sheet sheet : wb) { if (sheet.getSheetName().equals(SHEETNAME)) { for (Row row : sheet) { //stop with the first empty row if (row.getCell(0) == null) { break; } if (rowNumber >= -1) { rowNumber++; dataTable.add(new ArrayList<String>()); } for (Cell cell : row) { String sheetName = sheet.getSheetName(); String cellRow = "Row:" + cell.getRowIndex(); String cellColumn = "Column:" + cell.getColumnIndex(); Object[] o = new Object[] { sheetName, cellRow, cellColumn }; LOGGER.log(Level.INFO, "Processing: Sheet={0} celladress={1}", o); if (rowNumber <= -1 && cell.getCellType() == Cell.CELL_TYPE_BLANK) { continue; } if (rowNumber == -2 && cell.getCellType() == Cell.CELL_TYPE_STRING) { if (cell.getRichStringCellValue().getString().equals(DATACELLNAME)) { rowNumber = -1; continue; } } //Attributes (column headers) if (rowNumber == 0) { dataTable.get(rowNumber).add(cell.getRichStringCellValue().getString()); } if (rowNumber >= 1) { switch (cell.getCellType()) { case Cell.CELL_TYPE_STRING: dataTable.get(rowNumber).add(cell.getRichStringCellValue().getString()); break; case Cell.CELL_TYPE_NUMERIC: if (DateUtil.isCellDateFormatted(cell)) { dataTable.get(rowNumber).add(cell.getDateCellValue().toString()); } else { dataTable.get(rowNumber).add(Double.toString(cell.getNumericCellValue())); } break; case Cell.CELL_TYPE_BOOLEAN: dataTable.get(rowNumber).add(Boolean.toString(cell.getBooleanCellValue())); break; case Cell.CELL_TYPE_FORMULA: switch (cell.getCachedFormulaResultType()) { case Cell.CELL_TYPE_STRING: dataTable.get(rowNumber).add(cell.getRichStringCellValue().getString()); break; case Cell.CELL_TYPE_NUMERIC: if (DateUtil.isCellDateFormatted(cell)) { dataTable.get(rowNumber).add(cell.getDateCellValue().toString()); } else { dataTable.get(rowNumber).add(Double.toString(cell.getNumericCellValue())); } break; case Cell.CELL_TYPE_BOOLEAN: dataTable.get(rowNumber).add(Boolean.toString(cell.getBooleanCellValue())); break; default: dataTable.get(rowNumber).add(""); } break; default: dataTable.get(rowNumber).add(""); } } } } } } return dataTable; }
From source file:fr.openwide.core.export.excel.AbstractExcelTableExport.java
License:Apache License
/** * Ajoute un lien hypertexte sur la cellule. * //from w w w.ja v a 2s .c o m * @param cell cellule * @param hyperlink lien ajouter * @return cellule */ protected Cell addLinkToCell(Cell cell, Hyperlink hyperlink) { cell.setHyperlink(hyperlink); cell.setCellStyle(getRowStyle(STYLE_LINK_NAME, cell.getRowIndex())); return cell; }