List of usage examples for org.apache.poi.ss.usermodel Sheet rowIterator
Iterator<Row> rowIterator();
From source file:net.sibcolombia.sibsp.service.portal.implementation.ResourceManagerImplementation.java
License:Creative Commons License
private void readExternallinks(Eml eml, Workbook template) throws InvalidFormatException { Sheet sheet = template.getSheet("Enlaces externos"); eml.setDistributionUrl(readCellValue(sheet.getRow(5).getCell(1))); Iterator<Row> rowIterator = sheet.rowIterator(); Row row;//from w ww.ja va2 s . c o m List<PhysicalData> physicalDatas = new ArrayList<PhysicalData>(); PhysicalData physicalData = null; while (rowIterator.hasNext()) { row = rowIterator.next(); if (readCellValue(sheet.getRow(row.getRowNum()).getCell(1, Row.CREATE_NULL_AS_BLANK)) .equalsIgnoreCase("Nombre:")) { if (!readCellValue(sheet.getRow(row.getRowNum() + 1).getCell(1)).isEmpty() || !readCellValue(sheet.getRow(row.getRowNum() + 1).getCell(4)).isEmpty() || !readCellValue(sheet.getRow(row.getRowNum() + 3).getCell(1)).isEmpty() || !readCellValue(sheet.getRow(row.getRowNum() + 5).getCell(1)).isEmpty() || !readCellValue(sheet.getRow(row.getRowNum() + 5).getCell(4)).isEmpty()) { physicalData = new PhysicalData(); physicalData.setName(readCellValue(sheet.getRow(row.getRowNum() + 1).getCell(1))); physicalData.setCharset(readCellValue(sheet.getRow(row.getRowNum() + 1).getCell(4))); physicalData.setDistributionUrl(readCellValue(sheet.getRow(row.getRowNum() + 3).getCell(1))); physicalData.setFormat(readCellValue(sheet.getRow(row.getRowNum() + 5).getCell(1))); physicalData.setFormatVersion(readCellValue(sheet.getRow(row.getRowNum() + 5).getCell(4))); physicalDatas.add(physicalData); } } } eml.setPhysicalData(physicalDatas); }
From source file:net.sibcolombia.sibsp.service.portal.implementation.ResourceManagerImplementation.java
License:Creative Commons License
private void readKeywords(Eml eml, Workbook template) throws InvalidFormatException { Sheet sheet = template.getSheet("Palabras Clave"); List<KeywordSet> keywordsSet = new ArrayList<KeywordSet>(); KeywordSet keywordSet = null;// w ww . j a va2s . c o m Iterator<Row> rowIterator = sheet.rowIterator(); Row row; while (rowIterator.hasNext()) { row = rowIterator.next(); if (readCellValue(sheet.getRow(row.getRowNum()).getCell(1, Row.CREATE_NULL_AS_BLANK)) .equalsIgnoreCase("Tesauro *REQUERIDO:")) { row = rowIterator.next(); if (!readCellValue(sheet.getRow(row.getRowNum()).getCell(1)).isEmpty() && !readCellValue(sheet.getRow(row.getRowNum() + 2).getCell(1)).isEmpty()) { keywordSet = new KeywordSet(); keywordSet.setKeywordThesaurus(readCellValue(sheet.getRow(row.getRowNum()).getCell(1))); keywordSet.setKeywordsString(readCellValue(sheet.getRow(row.getRowNum() + 2).getCell(1))); keywordsSet.add(keywordSet); } } } eml.setKeywords(keywordsSet); }
From source file:net.sibcolombia.sibsp.service.portal.implementation.ResourceManagerImplementation.java
License:Creative Commons License
private void readSamplingMethods(Eml eml, Workbook template) throws InvalidFormatException { Sheet sheet = template.getSheet("Mtodos de Muestreo"); eml.setStudyExtent(readCellValue(sheet.getRow(5).getCell(1))); eml.setSampleDescription(readCellValue(sheet.getRow(7).getCell(1))); eml.setQualityControl(readCellValue(sheet.getRow(9).getCell(1))); List<String> methodSteps = new ArrayList<String>(); Iterator<Row> rowIterator = sheet.rowIterator(); Row row;// w w w . j a va2s .c o m while (rowIterator.hasNext()) { row = rowIterator.next(); if (readCellValue(sheet.getRow(row.getRowNum()).getCell(1, Row.CREATE_NULL_AS_BLANK)) .equalsIgnoreCase("Descripcin del Paso Metodolgico:")) { if (!readCellValue(sheet.getRow(row.getRowNum() + 1).getCell(1)).isEmpty()) { methodSteps.add(readCellValue(sheet.getRow(row.getRowNum() + 1).getCell(1))); } } } eml.setMethodSteps(methodSteps); }
From source file:net.sibcolombia.sibsp.service.portal.implementation.ResourceManagerImplementation.java
License:Creative Commons License
private void readTaxonomicCoverage(Eml eml, Workbook template) throws InvalidFormatException { Sheet sheet = template.getSheet("Cobertura Taxonmica"); List<TaxonomicCoverage> taxonomicCoverages = new ArrayList<TaxonomicCoverage>(); TaxonomicCoverage taxonomicCoverage = null; List<TaxonKeyword> keywords = null; TaxonKeyword taxonKeyword = null;/* w ww . ja v a 2 s. c o m*/ Iterator<Row> rowIterator = sheet.rowIterator(); Row row; while (rowIterator.hasNext()) { row = rowIterator.next(); if (readCellValue(sheet.getRow(row.getRowNum()).getCell(1, Row.CREATE_NULL_AS_BLANK)) .equalsIgnoreCase("Descripcin:")) { if (!readCellValue(sheet.getRow(row.getRowNum() + 1).getCell(1)).isEmpty()) { taxonomicCoverage = new TaxonomicCoverage(); taxonomicCoverage.setDescription(readCellValue(sheet.getRow(row.getRowNum() + 1).getCell(1))); keywords = new ArrayList<TaxonKeyword>(); row = rowIterator.next(); row = rowIterator.next(); while (readCellValue(sheet.getRow(row.getRowNum()).getCell(1, Row.CREATE_NULL_AS_BLANK)) .equalsIgnoreCase("Nombre cientfico *REQUERIDO:")) { row = rowIterator.next(); if (!readCellValue(sheet.getRow(row.getRowNum()).getCell(1)).isEmpty()) { taxonKeyword = new TaxonKeyword(); taxonKeyword.setScientificName(readCellValue(sheet.getRow(row.getRowNum()).getCell(1))); taxonKeyword.setCommonName(readCellValue(sheet.getRow(row.getRowNum()).getCell(4))); taxonKeyword.setRank(readCellValue(sheet.getRow(row.getRowNum()).getCell(7))); keywords.add(taxonKeyword); } row = rowIterator.next(); } taxonomicCoverage.setTaxonKeywords(keywords); taxonomicCoverages.add(taxonomicCoverage); } } } eml.setTaxonomicCoverages(taxonomicCoverages); }
From source file:net.sibcolombia.sibsp.service.portal.implementation.ResourceManagerImplementation.java
License:Creative Commons License
private void readTemporalCoverage(Eml eml, Workbook template) throws InvalidFormatException { Sheet sheet = template.getSheet("Cobertura Temporal"); List<TemporalCoverage> temporalCoverages = new ArrayList<TemporalCoverage>(); TemporalCoverage temporalCoverage = null; DateFormat dateFormatA = new SimpleDateFormat("MM/dd/yyyy"); DateFormat dateFormatB = new SimpleDateFormat("yyyy-MM-dd"); Iterator<Row> rowIterator = sheet.rowIterator(); Row row;// w w w. ja va2 s . c o m while (rowIterator.hasNext()) { row = rowIterator.next(); if (readCellValue(sheet.getRow(row.getRowNum()).getCell(1, Row.CREATE_NULL_AS_BLANK)) .equalsIgnoreCase("Tipo de cobertura temporal:")) { switch (readCellValue(sheet.getRow(row.getRowNum() + 1).getCell(1))) { case "Fecha Simple": try { temporalCoverage = new TemporalCoverage(); if (readCellValue(sheet.getRow(row.getRowNum() + 5).getCell(2)) .matches("\\d{4}-\\d{2}-\\d{2}")) { temporalCoverage.setStartDate(dateFormatB .parse(readCellValue(sheet.getRow(row.getRowNum() + 14).getCell(2)))); } else if (readCellValue(sheet.getRow(row.getRowNum() + 5).getCell(2)) .matches("\\d{2}/\\d{2}/\\d{4}")) { temporalCoverage.setStartDate(dateFormatA .parse(readCellValue(sheet.getRow(row.getRowNum() + 14).getCell(2)))); } else { throw new InvalidFormatException( "Error al procesar fecha inicial y final en cobertura temporal: "); } temporalCoverages.add(temporalCoverage); } catch (ParseException e) { throw new InvalidFormatException( "Error al procesar fecha inicial y final en cobertura temporal: " + e); } break; case "Perodo de Tiempo de Vida": temporalCoverage = new TemporalCoverage(); temporalCoverage .setLivingTimePeriod(readCellValue(sheet.getRow(row.getRowNum() + 8).getCell(2))); temporalCoverages.add(temporalCoverage); break; case "Perodo de Formacin": temporalCoverage = new TemporalCoverage(); temporalCoverage .setFormationPeriod(readCellValue(sheet.getRow(row.getRowNum() + 11).getCell(2))); temporalCoverages.add(temporalCoverage); break; case "Rango de Fechas": try { temporalCoverage = new TemporalCoverage(); if (readCellValue(sheet.getRow(row.getRowNum() + 14).getCell(2)) .matches("\\d{4}-\\d{2}-\\d{2}")) { temporalCoverage.setStartDate(dateFormatB .parse(readCellValue(sheet.getRow(row.getRowNum() + 14).getCell(2)))); } else if (readCellValue(sheet.getRow(row.getRowNum() + 14).getCell(2)) .matches("\\d{2}/\\d{2}/\\d{4}")) { temporalCoverage.setStartDate(dateFormatA .parse(readCellValue(sheet.getRow(row.getRowNum() + 14).getCell(2)))); } else { throw new InvalidFormatException( "Error al procesar fecha inicial y final en cobertura temporal: "); } if (readCellValue(sheet.getRow(row.getRowNum() + 14).getCell(5)) .matches("\\d{4}-\\d{2}-\\d{2}")) { temporalCoverage.setEndDate(dateFormatB .parse(readCellValue(sheet.getRow(row.getRowNum() + 14).getCell(5)))); } else if (readCellValue(sheet.getRow(row.getRowNum() + 14).getCell(5)) .matches("\\d{2}/\\d{2}/\\d{4}")) { temporalCoverage.setEndDate(dateFormatA .parse(readCellValue(sheet.getRow(row.getRowNum() + 14).getCell(5)))); } else { throw new InvalidFormatException( "Error al procesar fecha inicial y final en cobertura temporal: "); } temporalCoverages.add(temporalCoverage); } catch (ParseException e) { throw new InvalidFormatException( "Error al procesar fecha inicial y final en cobertura temporal: " + e); } break; default: break; } } } eml.setTemporalCoverages(temporalCoverages); }
From source file:nl.meine.scouting.solparser.writer.ExcelWriter.java
License:Open Source License
private void processUpdates(Sheet sheet) { System.out.println("Process updates on sheet: " + sheet.getSheetName()); if (hasPrevious()) { FileInputStream previousStream = null; HSSFWorkbook prevWorkbook = null; try {// w ww .j av a 2 s. c o m previousStream = new FileInputStream(previous); //Get the workbook instance for XLS file prevWorkbook = new HSSFWorkbook(previousStream); Sheet prevSheet = prevWorkbook.getSheet(SorterFactory.GROUP_NAME_ALL); if (prevSheet != null) { // Bestaande mensen: eventuele updates for (Iterator<Row> it = sheet.rowIterator(); it.hasNext();) { Row row = it.next(); if (row.getRowNum() > 0) { String lidnummer = row.getCell(NUM_LIDNUMMER_CELL).getStringCellValue(); Row previousRow = getLidFromSheet(lidnummer, prevSheet); processPersonUpdates(row, previousRow); } } } } catch (FileNotFoundException ex) { System.out.println("Could not locate file: " + ex.getLocalizedMessage()); } catch (IOException ex) { System.out.println("Problems reading file: " + ex.getLocalizedMessage()); } finally { try { if (previousStream != null) { previousStream.close(); if (prevWorkbook != null) { FileOutputStream out = new FileOutputStream(previous); prevWorkbook.write(out); out.close(); } } } catch (IOException ex) { System.out.println("Problems closing file: " + ex.getLocalizedMessage()); } } } }
From source file:nl.meine.scouting.solparser.writer.ExcelWriter.java
License:Open Source License
private Row getLidFromSheet(String lidnummer, Sheet sheet) { for (Iterator<Row> it = sheet.rowIterator(); it.hasNext();) { Row row = it.next();/*from w w w .j a v a 2 s .c o m*/ String oldLidnummer = row.getCell(NUM_LIDNUMMER_CELL).getStringCellValue(); if (lidnummer.equals(oldLidnummer)) { return row; } } return null; }
From source file:nu.mine.kino.projects.ExcelScheduleBeanSheet.java
License:Open Source License
public void init(Workbook workbook) throws ProjectException { instanceList = new ArrayList<ExcelScheduleBean>(); Sheet sheet = workbook.getSheetAt(0); Iterator<Row> e = sheet.rowIterator(); int index = 0; int dataIndex = PoiUtils.getDataFirstRowNum(sheet); int headerIndex = PoiUtils.getHeaderIndex(sheet); Row headerRow = null;//from w ww. j av a2 s. c om while (e.hasNext()) { // wb_?I?B if (index < headerIndex) { e.next(); index++; continue; } // header?AtZL?[l?B if (index == headerIndex) { headerRow = e.next(); dateFirstCellnum = findDateFirstCellnum(headerRow); dateLastCellNum = findDateLastCellnum(headerRow); projectStartDate = (Date) PoiUtil.getCellValue(headerRow.getCell(dateFirstCellnum)); projectEndDate = (Date) PoiUtil.getCellValue(headerRow.getCell(dateLastCellNum)); if (projectStartDate.getTime() > projectEndDate.getTime()) { String msg = String.format("v?WFNgJn>v?WFNg?I?B[%s][%s]", projectStartDate, projectEndDate); throw new ProjectException(msg); } index++; continue; } // wb_?I?B if (index < dataIndex) { e.next(); index++; continue; } // f?[^?? Row dataRow = e.next(); Cell taskIdCell = dataRow.getCell(1); String taskId = PoiUtils.getTaskId(taskIdCell); if (!StringUtils.isEmpty(taskId)) { ExcelScheduleBean bean = new ExcelScheduleBean(); bean.setTaskId(taskId); bean.setPlotDataMap(createPlotMap(headerRow, dataRow)); instanceList.add(bean); } } }
From source file:nu.mine.kino.projects.utils.POITest.java
License:Open Source License
@Test public void test5() throws InvalidFormatException, IOException { Sheet sheet = workbook.getSheetAt(0); Iterator<Row> e = sheet.rowIterator(); System.out.println("--- ?lneXg ---"); while (e.hasNext()) { Row row = e.next();// w w w.ja v a2 s. c om Cell taskIdCell = row.getCell(1); String taskId = getTaskId(taskIdCell); System.out.printf("[%s],[%s],[%s],[%s],[%s]\n", taskId, row.getCell(15), row.getCell(22), row.getCell(23), row.getCell(24)); } System.out.println("--- ?lneXg ---"); }
From source file:nu.mine.kino.projects.utils.POITest.java
License:Open Source License
@Test public void test6() throws InvalidFormatException, IOException { Sheet sheet = workbook.getSheetAt(0); Iterator<Row> e = sheet.rowIterator(); System.out.println("--- tneXg ---"); int index = 0; while (e.hasNext()) { Row row = e.next();// w w w . j a va 2s. c o m Cell taskIdCell = row.getCell(1); String taskId = getTaskId(taskIdCell); Cell scheduledSDateCell = row.getCell(16); Date sDate = getDate(scheduledSDateCell); Cell scheduledEDateCell = row.getCell(17); Date eDate = getDate(scheduledEDateCell); String pattern = "yyyy/MM/dd"; System.out.printf("[%s],[%s],[%s]\n", taskId, Utils.date2Str(sDate, pattern), Utils.date2Str(eDate, pattern)); index++; } System.out.println(index); System.out.println("--- tneXg ---"); }