Example usage for org.apache.poi.ss.usermodel Workbook getSheet

List of usage examples for org.apache.poi.ss.usermodel Workbook getSheet

Introduction

In this page you can find the example usage for org.apache.poi.ss.usermodel Workbook getSheet.

Prototype

Sheet getSheet(String name);

Source Link

Document

Get sheet with the given name

Usage

From source file:net.sibcolombia.sibsp.service.portal.implementation.ResourceManagerImplementation.java

License:Creative Commons License

private void readCollectionData(Eml eml, Workbook template) throws InvalidFormatException {
    Sheet sheet = template.getSheet("Datos de la Coleccin");
    eml.setCollectionName(readCellValue(sheet.getRow(5).getCell(1)));
    eml.setCollectionId(readCellValue(sheet.getRow(5).getCell(4)));
    eml.setParentCollectionId(readCellValue(sheet.getRow(7).getCell(1)));
    eml.setSpecimenPreservationMethod(readCellValue(sheet.getRow(7).getCell(4)));
    Iterator<Row> rowIterator = sheet.rowIterator();
    Row row;//from  ww  w . ja  v a 2 s  .c o m
    List<JGTICuratorialUnit> jgtiCuratorialUnits = new ArrayList<JGTICuratorialUnit>();
    JGTICuratorialUnit jgtiCuratorialUnit;
    while (rowIterator.hasNext()) {
        row = rowIterator.next();
        if (readCellValue(sheet.getRow(row.getRowNum()).getCell(1, Row.CREATE_NULL_AS_BLANK))
                .equalsIgnoreCase("Tipo de Mtodo:")) {
            switch (readCellValue(sheet.getRow(row.getRowNum() + 1).getCell(1))) {
            case "Rango de conteo":
                jgtiCuratorialUnit = new JGTICuratorialUnit();
                jgtiCuratorialUnit.setRangeStart(
                        (int) sheet.getRow(row.getRowNum() + 5).getCell(2).getNumericCellValue());
                jgtiCuratorialUnit
                        .setRangeEnd((int) sheet.getRow(row.getRowNum() + 5).getCell(4).getNumericCellValue());
                jgtiCuratorialUnit.setUnitType(readCellValue(sheet.getRow(row.getRowNum() + 5).getCell(6)));
                jgtiCuratorialUnits.add(jgtiCuratorialUnit);
                break;
            case "Conteo con incertidumbre":
                jgtiCuratorialUnit = new JGTICuratorialUnit();
                jgtiCuratorialUnit
                        .setRangeMean((int) sheet.getRow(row.getRowNum() + 8).getCell(2).getNumericCellValue());
                jgtiCuratorialUnit.setUncertaintyMeasure(
                        (int) sheet.getRow(row.getRowNum() + 8).getCell(4).getNumericCellValue());
                jgtiCuratorialUnit.setUnitType(readCellValue(sheet.getRow(row.getRowNum() + 8).getCell(6)));
                jgtiCuratorialUnits.add(jgtiCuratorialUnit);
                break;
            }
        }
    }
    eml.setJgtiCuratorialUnits(jgtiCuratorialUnits);
}

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 w  w.  java  2s .c om*/
    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 readGeographicCoverage(Eml eml, Workbook template) {
    Sheet sheet = template.getSheet("Cobertura Geogrfica");
    List<GeospatialCoverage> geospatialCoverageList = new ArrayList<GeospatialCoverage>();
    GeospatialCoverage geospatialCoverage = null;
    BBox boundingCoordinates = null;//from  w  ww  . ja v  a2 s  .c o  m
    geospatialCoverage = new GeospatialCoverage();
    boundingCoordinates = new BBox();
    geospatialCoverage.setDescription(sheet.getRow(9).getCell(1).getStringCellValue());
    geospatialCoverageList.add(geospatialCoverage);
    boundingCoordinates.setOrderedBounds(sheet.getRow(7).getCell(1).getNumericCellValue(),
            sheet.getRow(5).getCell(1).getNumericCellValue(), sheet.getRow(7).getCell(4).getNumericCellValue(),
            sheet.getRow(5).getCell(4).getNumericCellValue());
    geospatialCoverage.setBoundingCoordinates(boundingCoordinates);
    eml.setGeospatialCoverages(geospatialCoverageList);
}

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;/*from w  ww  .j  ava  2s .co 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 readProjectData(Eml eml, Workbook template) throws InvalidFormatException {
    Sheet sheet = template.getSheet("Datos del Proyecto");
    Project project = new Project();
    project.setTitle(readCellValue(sheet.getRow(5).getCell(1)));
    project.setFunding(readCellValue(sheet.getRow(11).getCell(1)));
    project.setDesignDescription(readCellValue(sheet.getRow(15).getCell(1)));
    Agent personnel = new Agent();
    personnel.setFirstName(readCellValue(sheet.getRow(7).getCell(1)));
    personnel.setLastName(readCellValue(sheet.getRow(7).getCell(4)));
    personnel.setRole(readCellValue(sheet.getRow(9).getCell(1)));
    project.setPersonnel(personnel);//  w  w w  .  ja  va  2  s .c  o  m
    StudyAreaDescription studyAreaDescription = new StudyAreaDescription();
    studyAreaDescription.setDescriptorValue(readCellValue(sheet.getRow(13).getCell(1)));
    project.setStudyAreaDescription(studyAreaDescription);
    eml.setProject(project);
}

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;//from  w  w w.  jav a2 s .c  om
    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;/*from   ww  w .j ava  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;/*  ww  w.  j  a  va  2s.com*/
    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:net.sourceforge.squirrel_sql.plugins.dataimport.importer.excel.ExcelFileImporter.java

License:Open Source License

private Sheet getSheet(Workbook wb) {
    Sheet s = null;/*from  w w w.  j a v  a 2  s. c  o m*/
    if (settings.getSheetName() != null) {
        s = wb.getSheet(settings.getSheetName());
    }
    if (s == null) {
        s = wb.getSheetAt(0);
    }
    return s;
}

From source file:nl.detoren.ijsco.io.ExcelImport.java

License:Open Source License

public GroepsUitslagen importeerUitslagen(File file) {

    GroepsUitslagen groepen = new GroepsUitslagen();
    try {//from   w w  w.  j ava2 s .  c o m

        FileInputStream excelFile = new FileInputStream(file);
        Workbook workbook = new XSSFWorkbook(excelFile);
        String versie = "onbekend";
        Sheet sheet = workbook.getSheet("Configuratie");
        try {
            versie = sheet.getRow(0).getCell(1).getStringCellValue();
        } catch (Exception ex) {
            logger.log(Level.INFO, "Indelings Excel versie ophalen mislukt");
        }
        logger.log(Level.INFO, "Indelings Excel is versie " + versie);
        for (int i = 0; i < workbook.getNumberOfSheets(); i++) {
            sheet = workbook.getSheetAt(i);
            if (sheet.getSheetName().startsWith("Groep ")) {
                logger.log(Level.INFO, "Importeer uitslag van groep : " + sheet.getSheetName());
                Row row = sheet.getRow(0);
                if (row != null) {
                    Cell cell = row.getCell(0);
                    if (cell != null) {
                        int groepsgrootte = (int) cell.getNumericCellValue();
                        logger.log(Level.INFO, "Groepsgrootte is " + groepsgrootte);
                        switch (groepsgrootte) {
                        case 4:
                            groepen.Add(importeerGroep4(sheet));
                            break;
                        case 6:
                            groepen.Add(importeerGroep6(sheet));
                            break;
                        case 8:
                            groepen.Add(importeerGroep8(sheet));
                            break;
                        case 10:
                            groepen.Add(importeerGroep10(sheet));
                            break;
                        default:
                            logger.log(Level.WARNING, "Uitslagen verwerken voor groepsgrootte " + groepsgrootte
                                    + " niet ondersteund!");
                            break;
                        }
                    }
                }
                logger.log(Level.INFO, "next");
            }
        }
        workbook.close();
    } catch (Exception ex) {
        logger.log(Level.SEVERE, "Exception! Cause: " + ex.getCause() + ". Internal error is " + ex.getMessage()
                + ". Stracktrace: \r\n" + Utils.stackTraceToString(ex));
    }
    // Print resultaat;
    logger.log(Level.INFO, groepen.toString());
    return groepen;
}