Example usage for org.apache.poi.ss.usermodel Cell getColumnIndex

List of usage examples for org.apache.poi.ss.usermodel Cell getColumnIndex

Introduction

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

Prototype

int getColumnIndex();

Source Link

Document

Returns column index of this cell

Usage

From source file:dk.cubing.liveresults.uploader.parser.WcaParser.java

License:Open Source License

/**
 * @param row//from www .ja v a 2s  .  c  o 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/*from www .  j  ava 2 s  .com*/
 *
 * @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
 *///ww  w .  ja va  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// w w w . java2s .c om
 */
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:energy.usef.pbcfeeder.PbcFeeder.java

License:Apache License

private void fillColStubInputMap(HSSFSheet pbcDataSheet) {
    stubColInputMap = new HashMap<>();
    for (Cell topRowCell : pbcDataSheet.getRow(0)) {
        if (topRowCell.getStringCellValue().equals("")) {
            break;
        }//from  w w w .  j a va  2  s  .  c  om
        String columnName = topRowCell.getStringCellValue();
        List<Double> colValues = new ArrayList<>();
        for (Row r : pbcDataSheet) {
            if (r.getRowNum() == 0) {
                continue;
            }
            Cell c = r.getCell(topRowCell.getColumnIndex());
            if (c != null) {
                if (c.getCellType() == Cell.CELL_TYPE_NUMERIC) {
                    colValues.add(c.getNumericCellValue());
                }
            }
        }
        stubColInputMap.put(columnName, colValues);
    }
}

From source file:energy.usef.pbcfeeder.PbcFeeder.java

License:Apache License

/**
 * This method fills in the map with CongestionPoint-->Lower Power Limit and the map CongestionPoint-->Upper Power Limit.
 *
 * @param pbcCongestionPointLimitsSheet the excel page with the power limits.
 *//*from w  ww. j a  va2s  .  c o  m*/
private void fillCongestionPointLimitsMaps(HSSFSheet pbcCongestionPointLimitsSheet) {
    congestionPointLowerLimitMap = new HashMap<>();
    congestionPointUpperLimitMap = new HashMap<>();
    for (Cell columnHeading : pbcCongestionPointLimitsSheet.getRow(0)) {
        // stop when one encounters the first empty cell.
        if (StringUtils.isBlank(columnHeading.getStringCellValue())) {
            break;
        }
        for (Row row : pbcCongestionPointLimitsSheet) {
            // skip first row.
            if (row.getRowNum() == 0) {
                continue;
            }
            String congestionPoint = row.getCell(0).getStringCellValue();
            Cell cell = row.getCell(columnHeading.getColumnIndex());
            if (LOWER_LIMIT.equals(columnHeading.getStringCellValue())) {
                congestionPointLowerLimitMap.put(congestionPoint, new BigDecimal(cell.getNumericCellValue()));
            }
            if (UPPER_LIMIT.equals(columnHeading.getStringCellValue())) {
                congestionPointUpperLimitMap.put(congestionPoint, new BigDecimal(cell.getNumericCellValue()));
            }
        }
    }
}

From source file:energy.usef.pbcfeeder.PbcFeeder.java

License:Apache License

private void fillPbcStubDataDto(Cell c, PbcStubDataDto row) {
    switch (c.getColumnIndex()) {
    case 0:/*  w  w  w .  jav  a  2  s .co  m*/
        row.setIndex((int) c.getNumericCellValue());
        break;
    case 1:
        row.setCongestionPointOne(c.getNumericCellValue());
        break;
    case 2:
        row.setCongestionPointTwo(c.getNumericCellValue());
        break;
    case 3:
        row.setCongestionPointThree(c.getNumericCellValue());
        break;
    case 4:
        row.setCongestionPointAvg(c.getNumericCellValue());
        break;
    case 5:
        row.setPvLoadForecast(c.getNumericCellValue());
        break;
    case 6:
        row.setPvLoadActual(c.getNumericCellValue());
        break;
    case 7:
        row.setApx(c.getNumericCellValue());
        break;
    default:
        break;
    }
}

From source file:eremeykin.pete.loader.xlsxdao.XlsxResultSet.java

public XlsxResultSet(XSSFSheet sheet) {
    this.sheet = sheet;
    currRow = sheet.getRow(0);//from   ww w  .j  a v  a2s.co m
    for (Cell cell : currRow) {
        colNameMap.put(cell.getStringCellValue(), cell.getColumnIndex());
    }
}

From source file:es.SSII2.manager.ExcelManagerAccount.java

public void readAccountExcel() throws FileNotFoundException, IOException {

    FileInputStream file;//from w  w w . ja v a  2  s . com
    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());

                }
            }
        }

    }
}