List of usage examples for org.apache.poi.ss.usermodel Row getRowNum
int getRowNum();
From source file:dk.cubing.liveresults.uploader.parser.WcaParser.java
License:Open Source License
/** * @param row//from w w w. j a v a 2 s .com * @param event * @return * @throws IllegalStateException */ private Result parseResultRow(Row row, Event event) throws IllegalStateException { Result result = new Result(); // competitor data for teams if (event.getName().toLowerCase().contains("team")) { parseTeamCompetitorData(row, result); // normal competitors } else { parseCompetitorData(row, result); } // only parse results for competitors with a name / country if (result.getFirstname() != null && result.getSurname() != null && result.getCountry() != null) { // handle special multiple blindfolded sheet if (event.getName().toLowerCase().contains("multi")) { // best of 1 if (Event.Format.BEST_OF_1.getValue().equals(event.getFormat())) { result.setResult1(parseResultCell(row, 5)); result.setBest(result.getResult1()); result.setRegionalSingleRecord(parseRecordCell(row, 4)); // best of 2 } else if (Event.Format.BEST_OF_2.getValue().equals(event.getFormat())) { result.setResult1(parseResultCell(row, 4)); result.setResult2(parseResultCell(row, 8)); result.setBest(parseResultCell(row, 9)); result.setRegionalSingleRecord(parseRecordCell(row, 10)); // unsupported format } else { log.warn("[{}] Unsupported format: {}", row.getSheet().getSheetName(), event.getFormat()); } // handle special team events } else if (event.getName().toLowerCase().contains("team")) { // best of 1 if (Event.Format.BEST_OF_1.getValue().equals(event.getFormat())) { result.setResult1(parseResultCell(row, 3 + 1)); result.setBest(result.getResult1()); result.setRegionalSingleRecord(parseRecordCell(row, 3 + 2)); // best of 2 } else if (Event.Format.BEST_OF_2.getValue().equals(event.getFormat())) { result.setResult1(parseResultCell(row, 3 + 1)); result.setResult2(parseResultCell(row, 3 + 2)); result.setBest(parseResultCell(row, 3 + 3)); result.setRegionalSingleRecord(parseRecordCell(row, 3 + 4)); // best of 3 } else if (Event.Format.BEST_OF_3.getValue().equals(event.getFormat())) { result.setResult1(parseResultCell(row, 3 + 1)); result.setResult2(parseResultCell(row, 3 + 2)); result.setResult3(parseResultCell(row, 3 + 3)); result.setBest(parseResultCell(row, 3 + 4)); result.setRegionalSingleRecord(parseRecordCell(row, 3 + 5)); // unsupported format } else { log.warn("[{}] Unsupported format: {}", row.getSheet().getSheetName(), event.getFormat()); } // average of 5 } else if (Event.Format.AVERAGE.getValue().equals(event.getFormat())) { result.setResult1(parseResultCell(row, 1)); result.setResult2(parseResultCell(row, 2)); result.setResult3(parseResultCell(row, 3)); result.setResult4(parseResultCell(row, 4)); result.setResult5(parseResultCell(row, 5)); result.setBest(parseResultCell(row, 6)); result.setRegionalSingleRecord(parseRecordCell(row, 7)); result.setWorst(parseResultCell(row, 8)); result.setAverage(parseResultCell(row, 9)); result.setRegionalAverageRecord(parseRecordCell(row, 10)); // best of 1 } else if (Event.Format.BEST_OF_1.getValue().equals(event.getFormat())) { result.setResult1(parseResultCell(row, 1)); result.setBest(result.getResult1()); result.setRegionalSingleRecord(parseRecordCell(row, 2)); // best of 2 } else if (Event.Format.BEST_OF_2.getValue().equals(event.getFormat())) { result.setResult1(parseResultCell(row, 1)); result.setResult2(parseResultCell(row, 2)); result.setBest(parseResultCell(row, 3)); result.setRegionalSingleRecord(parseRecordCell(row, 4)); // best of 3 } else if (Event.Format.BEST_OF_3.getValue().equals(event.getFormat())) { result.setResult1(parseResultCell(row, 1)); result.setResult2(parseResultCell(row, 2)); result.setResult3(parseResultCell(row, 3)); result.setBest(parseResultCell(row, 4)); result.setRegionalSingleRecord(parseRecordCell(row, 5)); // mean of 3 } else if (Event.Format.MEAN.getValue().equals(event.getFormat())) { result.setResult1(parseResultCell(row, 1)); result.setResult2(parseResultCell(row, 2)); result.setResult3(parseResultCell(row, 3)); result.setBest(parseResultCell(row, 4)); result.setRegionalSingleRecord(parseRecordCell(row, 5)); result.setAverage(parseResultCell(row, 6)); result.setRegionalAverageRecord(parseRecordCell(row, 7)); // unsupported format } else { log.error("[{}] Unsupported format: {}", row.getSheet().getSheetName(), event.getFormat()); } } else { log.debug("[{}] Skipping results for competitor with no name and/or country: Row: {}", row.getSheet().getSheetName(), row.getRowNum() + 1); } return result; }
From source file:dk.cubing.liveresults.uploader.parser.WcaParser.java
License:Open Source License
/** * @param row/*www.j a va 2 s.com*/ * @param result * @throws IllegalStateException */ private void parseCompetitorData(Row row, Result result) throws IllegalStateException { for (int i = 1; i < 4; i++) { Cell cell = row.getCell(i); if (cell != null && cell.getCellType() != Cell.CELL_TYPE_BLANK) { switch (i) { // parse name case 1: String name = cell.getStringCellValue(); if (name != null) { name = StringUtil.ucwords(name); if (name.lastIndexOf(' ') != -1) { result.setFirstname(StringUtil.parseFirstname(name)); result.setSurname(StringUtil.parseSurname(name)); log.debug("Found result for : {}", name); } else { log.error("[{}] Missing firstname and/or surname for row: {}", row.getSheet().getSheetName(), row.getRowNum() + 1); } } break; // parse iso country code case 2: String country = cell.getStringCellValue(); if (country != null) { String countryCode = null; if (country.length() > 2) { countryCode = getCountryUtil().getCountryCodeByName(country); } else { countryCode = getCountryUtil().getCountryByCode(country); } if (countryCode != null) { result.setCountry(countryCode); log.debug("Country: {} - {}", countryCode, country); } else { log.error("[{}] Missing country information for row: {}", row.getSheet().getSheetName(), row.getRowNum() + 1); } } break; // parse wca id case 3: String wcaId = cell.getStringCellValue(); if (wcaId != null) { wcaId = wcaId.trim(); if (wcaId.length() == 10) { Matcher m = wcaIdPattern.matcher(wcaId); if (m.find()) { result.setWcaId(wcaId); log.debug("WCA Id: {}", result.getWcaId()); } else { log.warn("[{}] Invalid wcaId format: {}", row.getSheet().getSheetName(), wcaId); } } else { log.warn("[{}] Entered WCA id has wrong length. Expected: 10, Was: {}. Row: {}", new Object[] { row.getSheet().getSheetName(), wcaId.length(), row.getRowNum() + 1 }); } } break; } } else { switch (i) { case 1: if (result.getCountry() != null) { log.error("[{}] Missing firstname and/or surname for row: {}", row.getSheet().getSheetName(), row.getRowNum() + 1); } break; case 2: if (result.getFirstname() != null) { log.error("[{}] Missing country information for row: {}", row.getSheet().getSheetName(), row.getRowNum() + 1); } break; case 3: // WCA ID are optional break; } } } }
From source file:dk.cubing.liveresults.uploader.parser.WcaParser.java
License:Open Source License
/** * @param row/*from w ww . j a v a 2 s .co m*/ * @param result * @throws IllegalStateException */ private void parseTeamCompetitorData(Row row, Result result) throws IllegalStateException { Cell nameCell1 = row.getCell(1); Cell nameCell2 = row.getCell(1 + 3); if ((nameCell1 != null && nameCell1.getCellType() != Cell.CELL_TYPE_BLANK) && (nameCell2 != null && nameCell2.getCellType() != Cell.CELL_TYPE_BLANK)) { String name1 = nameCell1.getStringCellValue(); String name2 = nameCell2.getStringCellValue(); if (name1 != null && name2 != null) { name1 = StringUtil.ucwords(name1); name2 = StringUtil.ucwords(name2); if (name1.lastIndexOf(' ') != -1 && name2.lastIndexOf(' ') != -1) { result.setFirstname( StringUtil.parseFirstname(name1) + " / " + StringUtil.parseFirstname(name2)); result.setSurname(StringUtil.parseSurname(name1) + " / " + StringUtil.parseSurname(name2)); log.debug("Found result for : {} / {}", name1, name2); } else { log.error("[{}] Missing firstname and/or surname for row: {}", row.getSheet().getSheetName(), row.getRowNum() + 1); } } } Cell countryCell1 = row.getCell(2); Cell countryCell2 = row.getCell(2 + 3); if ((countryCell1 != null && countryCell1.getCellType() != Cell.CELL_TYPE_BLANK) && (countryCell2 != null && countryCell2.getCellType() != Cell.CELL_TYPE_BLANK)) { String country1 = countryCell1.getStringCellValue(); String country2 = countryCell2.getStringCellValue(); if (country1 != null && country2 != null) { String countryCode1 = null; String countryCode2 = null; if (country1.length() > 2 && country2.length() > 2) { countryCode1 = getCountryUtil().getCountryCodeByName(country1); countryCode2 = getCountryUtil().getCountryCodeByName(country2); } else { countryCode1 = getCountryUtil().getCountryByCode(country1); countryCode2 = getCountryUtil().getCountryByCode(country2); } if (countryCode1 != null && countryCode2 != null) { result.setCountry(countryCode1); //TODO: for now we only support 1 country log.debug("Country: {} - {} / {} - {}", new Object[] { countryCode1, country1, countryCode1, country1 }); } else { log.error("[{}] Missing country information for row: {}", row.getSheet().getSheetName(), row.getRowNum() + 1); } } } Cell wcaIdCell1 = row.getCell(3); Cell wcaIdCell2 = row.getCell(3 + 3); if ((wcaIdCell1 != null && wcaIdCell1.getCellType() != Cell.CELL_TYPE_BLANK) && (wcaIdCell2 != null && wcaIdCell2.getCellType() != Cell.CELL_TYPE_BLANK)) { String wcaId1 = wcaIdCell1.getStringCellValue(); String wcaId2 = wcaIdCell2.getStringCellValue(); if (wcaId1 != null && wcaId2 != null) { wcaId1 = wcaId1.trim(); wcaId2 = wcaId2.trim(); if (wcaId1.length() == 10 && wcaId2.length() == 10) { Matcher m1 = wcaIdPattern.matcher(wcaId1); Matcher m2 = wcaIdPattern.matcher(wcaId2); if (m1.find() && m2.find()) { result.setWcaId(wcaId1); // FIXME: for now only 1 wcaId are supported log.debug("WCA Id: {} / {}", wcaId1, wcaId2); } else { log.warn("[{}] Invalid wcaId format: {} / {}", new Object[] { row.getSheet().getSheetName(), wcaId1, wcaId2 }); } } else { log.warn("[{}] Entered WCA id has wrong length. Expected: 10, Was: {} / {}. Row: {}", new Object[] { row.getSheet().getSheetName(), wcaId1.length(), wcaId2.length(), row.getRowNum() + 1 }); } } } }
From source file:ec.sirec.web.impuestos.GestionAlcabalasControlador.java
public void postProcessXLS(Object document) { XSSFWorkbook wb = (XSSFWorkbook) document; XSSFSheet sheet = wb.getSheetAt(0); //Creo variable hoja ()contiene los atributos para la hoja de calculo List<String> encabezadoColumna = new ArrayList<String>(); for (Row row : sheet) { //Recorre los valores de la fila 1 (encabezado) pero en dataTable=0 if (row.getRowNum() == 0) { for (Cell cell : row) { encabezadoColumna.add(cell.getStringCellValue() + " "); }/*from www. j a v a2s. c o m*/ } else { break; } } //----inicio crea estilo XSSFCellStyle style = wb.createCellStyle(); //Se crea el estilo XSSFFont font = wb.createFont(); font.setBoldweight(XSSFFont.BOLDWEIGHT_BOLD); font.setColor(IndexedColors.WHITE.getIndex()); style.setFont(font); byte[] rgb = new byte[3]; rgb[0] = (byte) 076; rgb[1] = (byte) 145; rgb[2] = (byte) 065; XSSFColor myColor = new XSSFColor(rgb); style.setFillForegroundColor(myColor); style.setFillPattern(XSSFCellStyle.SOLID_FOREGROUND); XSSFRow row0 = sheet.createRow((short) 0); //Creo una fila en la posicion 0 //----fin crea estilo for (int i = 0; i <= encabezadoColumna.size() - 1; i++) { createCell(row0, i, encabezadoColumna.get(i), style); //agrego celdas en la posicion indicada con los valores de los encabezados } //Ajusta el ancho de las columnas for (int i = 0; i < 20; i++) { sheet.autoSizeColumn((short) i); } }
From source file:ec.util.spreadsheet.poi.PoiSheet.java
License:EUPL
public PoiSheet(@Nonnull Sheet sheet) { this.sheet = sheet; this.flyweightCell = new PoiCell(); int maxRow = 0; int maxColumn = 0; Iterator<Row> rowIterator = sheet.rowIterator(); while (rowIterator.hasNext()) { Row row = rowIterator.next(); maxRow = row.getRowNum() + 1; short lastCellNum = row.getLastCellNum(); if (lastCellNum > maxColumn) { maxColumn = lastCellNum;//from w w w.ja v a 2 s.co m } } this.rowCount = maxRow; this.columnCount = maxColumn; }
From source file:edu.gatech.pmase.capstone.awesome.impl.database.AbstractDatabaseDriver.java
License:Open Source License
/** * Reads the custom attribute values from the custom attribute sheet. * * @param wb the workbook to read the custom attributes from *//*from w w w . j a v a 2 s .co m*/ protected synchronized void setCustomAttributes(final Workbook wb) { LOGGER.info("Loading custom attribute list"); customAttributes.clear(); final Sheet customSheet = wb.getSheetAt(CUSTOM_ATTR_SHEET_NUM); if (null != customSheet) { LOGGER.debug("Custom attribute list stored in sheet: " + customSheet.getSheetName()); final int maxRows = customSheet.getPhysicalNumberOfRows(); if (maxRows > 1) { for (int rowIter = 1; rowIter < maxRows; rowIter++) { final Row row = customSheet.getRow(rowIter); if (null != row) { try { customAttributes.add(AbstractDatabaseDriver.getAttributeDescriptionFromRow(row)); } catch (ClassNotFoundException ex) { LOGGER.error("Could not load custom attribute for row: " + row.getRowNum(), ex); } } } } } else { LOGGER.warn("Could not load customer sheet"); } }
From source file:edu.gatech.pmase.capstone.awesome.impl.database.AbstractDatabaseDriver.java
License:Open Source License
/** * Gets the custom attributes from the given row. * * @param row the row to read from/*from ww w. j a v a 2 s .c o m*/ * * @return the list of gathered custom attributes. */ protected List<ArchitectureOptionAttribute> getCustomAttributes(final Row row) { final List<ArchitectureOptionAttribute> attrList = new ArrayList<>(customAttributes.size()); final StringBuilder attrLabels = new StringBuilder(); for (final ArchitectureOptionAttribute attr : customAttributes) { final Cell cell = row.getCell(attr.getColNum()); try { final ArchitectureOptionAttribute cpy = new ArchitectureOptionAttribute(attr); if (cpy.getType().equals(String.class)) { cpy.setValue(cell.getStringCellValue()); cpy.setOriginalValue(cell.getStringCellValue()); } else if (cpy.getType().equals(Double.class)) { cpy.setValue(cell.getNumericCellValue()); cpy.setOriginalValue(cell.getNumericCellValue()); } else { LOGGER.warn("Unable to read custom attributes for row: " + row.getRowNum() + ". Unknown cell type: " + cpy.getType().getName()); } attrList.add(cpy); if (attrList.isEmpty()) { attrLabels.append("--"); } else { attrLabels.append(", "); } attrLabels.append(cpy.getLabel()); } catch (ClassNotFoundException ex) { LOGGER.warn("Unable to read custom attributes for row: " + row.getRowNum(), ex); } } LOGGER.debug("Read " + attrList.size() + " custom attributes for row: " + row.getRowNum() + attrLabels.toString()); return attrList; }
From source file:edu.gatech.pmase.capstone.awesome.impl.database.CommunicationsDatabaseDriver.java
License:Open Source License
@Override protected CommunicationOption getOptionFromRow(final Row row) { CommunicationOption option = null;/*from w w w . ja v a 2s. com*/ // load required info final Cell idCell = row.getCell(ID_CELL_NUM); final Cell labelCell = row.getCell(LABEL_CELL_NUM); final Cell costRankCell = row.getCell(COST_RANK_CELL_NUM); final Cell weightCell = row.getCell(WEIGHT_CELL_NUM); if (null == idCell || null == labelCell || null == costRankCell || null == weightCell) { LOGGER.trace( "Comm Database Row " + row.getRowNum() + " missing required CommunicationsOption information."); } else { option = new CommunicationOption(); final long idNum = (long) idCell.getNumericCellValue(); LOGGER.debug("Parsing CommunicationsOption with ID: " + idNum); option.setId(idNum); option.setLabel(labelCell.getStringCellValue()); option.setCostRanking((int) costRankCell.getNumericCellValue()); option.setWeight(weightCell.getNumericCellValue()); // get custom attributes option.setCustomAttributes(this.getCustomAttributes(row)); // load optional info // platform restrictions option.setPlatformLimitations( this.getPlatFormRestrictFromCell(row.getCell(PLAT_RESTRICT_CELL_NUM), platformOptions)); // terrain effects final List<TerrainEffect> terrainLimitation = new ArrayList<>(); terrainLimitation.addAll(this.getTerrainEffectsFromCell(row.getCell(TERRAIN_ONE_RESTRICT_CELL_NUM), 1)); terrainLimitation.addAll(this.getTerrainEffectsFromCell(row.getCell(TERRAIN_TWO_RESTRICT_CELL_NUM), 2)); terrainLimitation .addAll(this.getTerrainEffectsFromCell(row.getCell(TERRAIN_THREE_RESTRICT_CELL_NUM), 3)); terrainLimitation .addAll(this.getTerrainEffectsFromCell(row.getCell(TERRAIN_FOUR_RESTRICT_CELL_NUM), 4)); LOGGER.debug("Found " + terrainLimitation.size() + " total Terrian Effect Restrictions for CommunicationsOption"); option.setTerrainLimitation(terrainLimitation); // disaster effect restrictions option.setDisasterLimitations( this.getDisasterEffectRestrictFromCell(row.getCell(DISASTER_EFFECT_RESTRICT_CELL_NUM))); } return option; }
From source file:edu.gatech.pmase.capstone.awesome.impl.database.PlatformDatabaseDriver.java
License:Open Source License
/** * Creates a PlatformOption from a row.//from ww w. j a v a2 s.co m * * @param row the row to transform * * @return the created PlatformOption, or null if cannot read the row. */ @Override protected PlatformOption getOptionFromRow(Row row) { PlatformOption option = null; // load required info final Cell idCell = row.getCell(ID_CELL_NUM); final Cell labelCell = row.getCell(LABEL_CELL_NUM); final Cell typeCell = row.getCell(TYPE_CELL_NUM); final Cell costRankCell = row.getCell(COST_RANKING_CELL_NUM); final Cell payloadCell = row.getCell(PAYLOAD_CELL_NUM); if (null == idCell || null == labelCell || null == typeCell || null == costRankCell || null == payloadCell || idCell.getCellType() == Cell.CELL_TYPE_BLANK) { LOGGER.trace( "Platform Database Row " + row.getRowNum() + " missing required PlatformOption information."); } else { option = new PlatformOption(); final long idNum = (long) idCell.getNumericCellValue(); LOGGER.debug("Parsing PlatformOption with ID: " + idNum); option.setId(idNum); option.setLabel(labelCell.getStringCellValue()); option.setCostRanking((int) costRankCell.getNumericCellValue()); option.setPayload(payloadCell.getNumericCellValue()); // set Platform Type option.setPlatformType(PlatformDatabaseDriver.getPlatformType(typeCell)); // set custom attributes option.setCustomAttributes(this.getCustomAttributes(row)); // load optional info // terrain effects final List<TerrainEffect> terrainLimitation = new ArrayList<>(); terrainLimitation.addAll(this.getTerrainEffectsFromCell(row.getCell(TERRAIN_ONE_RESTRICT_CELL_NUM), 1)); terrainLimitation.addAll(this.getTerrainEffectsFromCell(row.getCell(TERRAIN_TWO_RESTRICT_CELL_NUM), 2)); terrainLimitation .addAll(this.getTerrainEffectsFromCell(row.getCell(TERRAIN_THREE_RESTRICT_CELL_NUM), 3)); terrainLimitation .addAll(this.getTerrainEffectsFromCell(row.getCell(TERRAIN_FOUR_RESTRICT_CELL_NUM), 4)); LOGGER.debug( "Found " + terrainLimitation.size() + " total Terrian Effect Restrictions for PlatformOption"); option.setTerrainLimitation(terrainLimitation); // disaster effect restrictions option.setDisasterLimitations( this.getDisasterEffectRestrictFromCell(row.getCell(DISASTER_EFFECT_RESTRICT_CELL_NUM))); } return option; }
From source file:edu.gatech.pmase.capstone.awesome.impl.database.SensorsDatabaseDriver.java
License:Open Source License
/** * Creates a SensorOption from a row.//from w w w .ja va 2 s . c om * * @param row the row to transform * * @return the created SensorOption, or null if cannot read the row. */ @Override protected SensorOption getOptionFromRow(final Row row) { SensorOption option = null; // load required info final Cell idCell = row.getCell(ID_CELL_NUM); final Cell labelCell = row.getCell(LABEL_CELL_NUM); final Cell costRankCell = row.getCell(COST_RANK_CELL_NUM); final Cell weightCell = row.getCell(WEIGHT_CELL_NUM); if (null == idCell || null == labelCell || null == costRankCell || null == weightCell || idCell.getCellType() == Cell.CELL_TYPE_BLANK) { LOGGER.trace("Sensor Database Row " + row.getRowNum() + " missing required SensorOption information."); } else { option = new SensorOption(); final long idNum = (long) idCell.getNumericCellValue(); LOGGER.debug("Parsing SensorOption with ID: " + idNum); option.setId(idNum); option.setLabel(labelCell.getStringCellValue()); option.setCostRanking((int) costRankCell.getNumericCellValue()); option.setWeight(weightCell.getNumericCellValue()); // set custom attributes option.setCustomAttributes(this.getCustomAttributes(row)); // load optional info // platform restrictions option.setPlatformLimitations( this.getPlatFormRestrictFromCell(row.getCell(PLAT_RESTRICT_CELL_NUM), platformOptions)); // terrain effects final List<TerrainEffect> terrainLimitation = new ArrayList<>(); terrainLimitation.addAll(this.getTerrainEffectsFromCell(row.getCell(TERRAIN_ONE_RESTRICT_CELL_NUM), 1)); terrainLimitation.addAll(this.getTerrainEffectsFromCell(row.getCell(TERRAIN_TWO_RESTRICT_CELL_NUM), 2)); terrainLimitation .addAll(this.getTerrainEffectsFromCell(row.getCell(TERRAIN_THREE_RESTRICT_CELL_NUM), 3)); terrainLimitation .addAll(this.getTerrainEffectsFromCell(row.getCell(TERRAIN_FOUR_RESTRICT_CELL_NUM), 4)); LOGGER.debug( "Found " + terrainLimitation.size() + " total Terrian Effect Restrictions for SensorOption"); option.setTerrainLimitation(terrainLimitation); // disaster effect restrictions option.setDisasterLimitations( this.getDisasterEffectRestrictFromCell(row.getCell(DISASTER_EFFECT_RESTRICT_CELL_NUM))); } return option; }