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:net.unit8.axebomber.parser.TableHeader.java

License:Apache License

public TableHeader(Cell labelCell, Object labelPattern) {
    this.labelPattern = labelPattern;
    this.labelRowIndex = labelCell.getRowIndex() + 1;
    this.labelColumnIndex = labelCell.getColumnIndex();
    this.sheet = labelCell.getSubstance().getSheet();
    Cell beginCell = getCell(labelCell.getColumnIndex(), labelRowIndex);
    scanColumnLabel(beginCell);// w  ww.  j a v  a  2  s.  com
}

From source file:nl.meine.scouting.solparser.writer.ExcelWriter.java

License:Open Source License

private void processPersonUpdates(Row newRow, Row oldRow) {
    String newSpeltak = newRow.getCell(NUM_SPELTAK_CELL).getStringCellValue();
    boolean isNew = oldRow == null;
    boolean isOvervlieger = false;
    if (!isNew) {
        String previousSpeltak = oldRow.getCell(NUM_SPELTAK_CELL).getStringCellValue();
        ;/*from  ww  w.  j a v  a2  s . c  o  m*/
        if (!previousSpeltak.equals(newSpeltak)) {
            isOvervlieger = true;
        }
    }

    for (Iterator<Cell> it = newRow.cellIterator(); it.hasNext();) {
        Cell newCell = it.next();
        if (isNew) {
            updateCellColor(newCell, COLOR_NEW);
        } else {
            int colIndex = newCell.getColumnIndex();
            Cell oldCell = oldRow.getCell(colIndex);
            String newValue = newCell.getStringCellValue();
            String oldValue = oldCell.getStringCellValue();
            if (isOvervlieger) {
                updateCellColor(newCell, COLOR_OVERVLIEGER);
            }
            if (!newValue.equals(oldValue) && colIndex != NUM_SPELTAK_CELL) {
                updateCellColor(newCell, COLOR_UPDATED);
            }

        }
    }
}

From source file:nl.rabobank.fixtures.aiep.testdata.traffic.LicensePlateDataLoader.java

public void fetchTestData() throws MalformedURLException, IOException {

    InputStream excelFileToRead = null;

    if (isTest) {
        excelFileToRead = getClass().getResourceAsStream("/aiep_testdata_fitnesse.xlsx");
    } else {//from w w  w  . j a va2 s  .c o m
        excelFileToRead = new URL(TestDataLoader.TESTDATAPATH).openStream();
    }

    XSSFWorkbook wb = new XSSFWorkbook(excelFileToRead);
    XSSFSheet sheet = wb.getSheetAt(0);

    Iterator<Row> rows = sheet.rowIterator();
    boolean newRow = true;

    List<Row> myRowList = Lists.newArrayList(rows);

    if (this.testStubObject != null) {
        for (Row row : myRowList) {
            Iterator<Cell> cells = row.cellIterator();
            List<Cell> myRowCellsList = Lists.newArrayList(cells);

            for (Cell cell : myRowCellsList) {
                cell.setCellType(Cell.CELL_TYPE_STRING);

                if (cell.getStringCellValue().equals(this.testStubObject) && cell.getColumnIndex() == 0) {
                    newRow = false;
                }
                if (cell.getColumnIndex() == 1 && !newRow) {
                    setLicenseplate(cell.getStringCellValue());
                }
                if (cell.getColumnIndex() == 2 && !newRow) {
                    setBrand(cell.getStringCellValue());
                }
                if (cell.getColumnIndex() == 3 && !newRow) {
                    setModel(cell.getStringCellValue());
                }
                if (cell.getColumnIndex() == 4 && !newRow) {
                    setType(cell.getStringCellValue());
                }
                if (cell.getColumnIndex() == 5 && !newRow) {
                    setGear(cell.getStringCellValue());
                }
                if (cell.getColumnIndex() == 6 && !newRow) {
                    setFuel(cell.getStringCellValue());
                }
                if (cell.getColumnIndex() == 7 && !newRow) {
                    setProductionYear(cell.getStringCellValue());
                }
                if (cell.getColumnIndex() == 8 && !newRow) {
                    setPurchaseYear(cell.getStringCellValue());
                }
                if (cell.getColumnIndex() == 9 && this.testStubObject.startsWith("Motor") && !newRow) {
                    setSideCarValue(cell.getStringCellValue());
                }
                if (cell.getColumnIndex() == 10 && this.testStubObject.startsWith("Trailer")) {
                    setChassisNumber(cell.getStringCellValue());
                }
                if (cell.getColumnIndex() == 11 && !newRow) {
                    setWeight(cell.getStringCellValue());
                }
                if (cell.getColumnIndex() == 12 && !newRow) {
                    setPurchaseValue(cell.getStringCellValue());
                }
                if (cell.getColumnIndex() == 13 && !newRow) {
                    setInsuredInventory(cell.getStringCellValue());
                }
                if (cell.getColumnIndex() == 14 && !newRow) {
                    setSameLicensePlateAsCar(cell.getStringCellValue());
                }
                if (cell.getColumnIndex() == 15 && !newRow) {
                    setCatalogueValue(cell.getStringCellValue());
                }
                if (cell.getColumnIndex() == 16 && !newRow) {
                    setBodyShape(cell.getStringCellValue());
                }
            }
            if (!newRow) {
                break;
            }
        }
    }
    excelFileToRead.close();
}

From source file:npv.importer.XlsImporter.java

private Double[] parseFile() throws IOException {
    InputStream inputStream = new FileInputStream(file);
    POIFSFileSystem fs = new POIFSFileSystem(inputStream);
    HSSFWorkbook wb = new HSSFWorkbook(fs);
    HSSFSheet sheet = wb.getSheetAt(0);/* w  ww  .  j  a  v a2 s.c  o m*/
    System.out.println("Testing.First row num=" + sheet.getFirstRowNum());
    findTag(sheet, tag);

    //reading an array of Ri values after '#Ri' tag
    HSSFRow row = sheet.getRow(rPosition[0]);
    ArrayList<Double> cellValues = new ArrayList<Double>();

    Iterator<Cell> cellIterator = row.cellIterator();
    while (cellIterator.hasNext()) {
        Cell cell = cellIterator.next();
        if (cell.getColumnIndex() >= rPosition[1] + 1) {
            cellValues.add(cell.getNumericCellValue());
        }
    }

    rValues = new Double[cellValues.size()];
    rValues = cellValues.toArray(new Double[rValues.length]);
    System.out.println("Values from sheet:");
    for (int i = 0; i < rValues.length; i++) {
        System.out.println(rValues[i]);
    }

    return this.rValues;
}

From source file:npv.importer.XlsImporter.java

private void findTag(HSSFSheet sheet, String searchTag) {
    //looking for '#Ri' tag
    HSSFRow row = sheet.getRow(0);/*from   w w w  .  ja  v a2  s. co m*/
    Iterator<Row> rowIterator = sheet.iterator();
    Iterator<Cell> cellIterator;
    boolean isFound = false;

    while (rowIterator.hasNext()) {
        if (!isFound) {
            Row rRow = rowIterator.next();
            cellIterator = rRow.cellIterator();
            while (cellIterator.hasNext()) {
                Cell rCell = cellIterator.next();
                if (rCell.getCellType() == Cell.CELL_TYPE_STRING && rCell.getStringCellValue().equals(tag)) {
                    rPosition[0] = rRow.getRowNum();
                    rPosition[1] = rCell.getColumnIndex();
                    isFound = true;
                    break;
                }
            }
        } else {
            break;
        }
    }
}

From source file:offishell.excel.Excel.java

License:MIT License

/**
 * <p>/*  w w  w  .  j av a  2  s .  c  o  m*/
 * Search column index by the specified header text.
 * </p>
 * 
 * @param name
 * @return
 */
private int indexOfHeader(String name) {
    XSSFRow header = sheet.getRow(0);

    for (Cell cell : header) {
        if (name.equals(cell.getStringCellValue())) {
            return cell.getColumnIndex();
        }
    }
    return -1;
}

From source file:optimizador.optimizadordirecciones.co.com.optimizador.util.LeerExcel.java

/**
 * Asigna los datos al objeto.//from www . java 2s  . co m
 * 
 * @param vo
 * @param cell
 */
private void asignarDatos(Predio vo, Cell cell) {
    switch (cell.getColumnIndex()) {
    case 0:
        double con = cell.getNumericCellValue();
        vo.setIdContrato(String.valueOf(con));
        break;
    case 1:
        double plan = cell.getNumericCellValue();
        vo.setIdPlan(String.valueOf(plan));
        break;
    case 2:
        vo.setLocalidad(cell.getStringCellValue());
        break;
    case 3:
        vo.setSuscritor(cell.getStringCellValue());
        break;
    case 4:
        vo.setVisitado(cell.getStringCellValue());
        break;
    case 5:
        vo.setDireccion(cell.getStringCellValue());
        break;
    case 6:
        double v = cell.getNumericCellValue();
        vo.setVenAforo(String.valueOf(v));
        break;
    case 7:
        vo.setNumHabitacionales(cell.getStringCellValue());
        break;
    case 8:
        vo.setNumNoHabitaconales(cell.getStringCellValue());
        break;
    case 9:
        String tmp = cell.getStringCellValue();
        // vo.setProdBasura(Double.parseDouble(tmp));
        vo.setProdBasura(tmp);
        break;
    case 10:
        double ns = cell.getNumericCellValue();
        vo.setNumSemana(String.valueOf(ns));
        break;
    case 11:
        vo.setTipoAforo(cell.getStringCellValue());
        break;
    case 12:
        vo.setFrecuencia(cell.getStringCellValue());
        break;
    case 13:
        vo.setHorario(cell.getStringCellValue());
        break;
    }
}

From source file:org.ado.minesync.translation.ExportFile.java

License:Open Source License

private String getCodeEntryName(XSSFSheet sheet, Cell cell) {
    return sheet.getRow(CODE_COL).getCell(cell.getColumnIndex()).getStringCellValue();
}

From source file:org.agmip.ui.afsirs.others.ParseExcelToWeatherFileFormat.java

private static void ParseRain() {
    try {//w  w w.  j a  v  a  2  s .  com
        FileInputStream fs = new FileInputStream(rainFilePath);
        Workbook wb = new XSSFWorkbook(fs);
        Sheet sheet = wb.getSheetAt(0);
        String str = "ORLANDO     DAILY POTENTIAL RAIN DATA (INCHES), 1952-2015" + EOL;
        Iterator rowIterator = sheet.iterator();
        int outputcol = 0; // This will go from 1 - 14 in a row
        int outputElems = 0; // This will go from 1-365 and once this is 
        int overallRow = 0; // Total Number of Row processed
        int startYr = 0; // This will hold the First Year
        int endYr = 0; // This will hold the last Year

        while (rowIterator.hasNext()) {
            Row row = (Row) rowIterator.next();
            Iterator cellIterator = row.cellIterator();
            int month = 0;
            int date = 0;
            int year = 0;
            overallRow++;
            if (overallRow <= 4) {

                continue;
            }
            while (cellIterator.hasNext()) {
                Cell cell = (Cell) cellIterator.next();
                int colIndex = cell.getColumnIndex();
                if (Cell.CELL_TYPE_NUMERIC == cell.getCellType()) {

                    //This holds the Month Number
                    if (colIndex == 3) {
                        month = (int) cell.getNumericCellValue();
                    }
                    // This Date of the month // Skip if this is a Leap yeaar
                    else if (colIndex == 4) {
                        date = (int) cell.getNumericCellValue();

                        if (year % 4 == 0 && month == 2 && date == 29) {
                            break;
                        }
                    }
                    // Year
                    else if (colIndex == 2) {
                        year = (int) cell.getNumericCellValue();
                        if (endYr != year) {
                            endYr = year;
                            outputElems = 0;
                            outputcol = 0;
                            str += year + EOL;
                        }
                        if (startYr == 0) {
                            startYr = year;
                            endYr = year;
                        }

                        //student.setEnglish(String.valueOf(cell.getNumericCellValue()));
                    } else if (colIndex == 7) {

                        Double val = cell.getNumericCellValue();
                        str += " " + String.format("%.3f", val);
                        outputcol++;
                        outputElems++;

                        if (outputcol == 14) {
                            str += EOL;
                            outputcol = 0;
                        }
                        System.out.println("Value = " + val + EOL);
                        if (outputElems == 365) {
                            outputElems = 0;
                            outputcol = 0;
                            str += EOL;
                            System.out.println("--------------" + EOL);
                        }

                    }
                } /*else if (colIndex == 6) {
                          
                   Double val = Double.valueOf(cell.getStringCellValue());
                      str+= " " + String.format("%.3f", val);
                      outputcol++;
                      outputElems++;
                              
                              
                      // if 365
                              
                      // if 14
                      if (outputcol==14) {
                          str+=EOL;
                          outputcol=0;
                      }
                      System.out.println ("Value = " + val + EOL);
                      if (outputElems==365){
                          outputElems = 0;
                          outputcol = 0;
                          str+=EOL;
                          System.out.println ("--------------" + EOL);
                      }
                          
                  }*/
            }
            //System.out.println (" Column " + outputcol + " Element Number " + outputElems + EOL);
            overallRow++;
        }
        //String line2 = String.format("   %d   YEARS OF RECORD"+EOL, (endYr-startYr+1));
        //str = line2+str;
        writer.print(str);
    } catch (Exception ioe) {
        ioe.printStackTrace();
    } finally {
        writer.close();
    }
}

From source file:org.agmip.ui.afsirs.others.ParseExcelToWeatherFileFormat.java

private static void ParseETP() {
    try {/*from  ww w .j  a v a  2  s.  c  om*/
        FileInputStream fs = new FileInputStream(etFilePath);
        Workbook wb = new XSSFWorkbook(fs);
        Sheet sheet = wb.getSheetAt(0);
        writer = new PrintWriter("CLIM.ORL", "UTF-8");

        String str = "ORLANDO     DAILY POTENTIAL ET DATA (INCHES), 1952-2015" + EOL;

        writer.print(str);

        Iterator rowIterator = sheet.iterator();

        // We will skip the leap year Entry

        int outputcol = 0; // This will go from 1 - 14 in a row
        int outputElems = 0; // This will go from 1-365 and once this is 

        int overallRow = 1; // Total Number of Row processed
        int startYr = 0; // This will hold the First Year
        int endYr = 0; // This will hold the last Year

        //int yrEntry = 0;        // This should go till 365;
        str = "";
        while (rowIterator.hasNext()) {

            Row row = (Row) rowIterator.next();
            Iterator cellIterator = row.cellIterator();

            int month = 0;
            int date = 0;
            int year = 0;

            if (overallRow <= 4) {
                overallRow++;
                continue;
            }

            while (cellIterator.hasNext()) {

                Cell cell = (Cell) cellIterator.next();
                //The Cell Containing String will is name.
                if (Cell.CELL_TYPE_STRING == cell.getCellType()) {
                    //student.setName(cell.getStringCellValue());
                    String val = cell.getStringCellValue();
                    writer.print(val + " ");

                    //The Cell Containing numeric value will contain marks
                } else if (Cell.CELL_TYPE_NUMERIC == cell.getCellType()) {

                    int colIndex = cell.getColumnIndex();

                    //This holds the Month Number
                    if (colIndex == 0) {
                        month = (int) cell.getNumericCellValue();
                    }

                    // This Date of the month // Skip if this is a Leap yeaar
                    else if (colIndex == 1) {
                        date = (int) cell.getNumericCellValue();
                    }

                    // Year
                    else if (colIndex == 2) {
                        year = (int) cell.getNumericCellValue();
                        if (startYr == 0) {
                            startYr = year;
                            endYr = year;
                        } else {
                            endYr = year;
                        }

                        if (outputElems == 0) {
                            str += year + EOL;
                        }

                        if (year % 4 == 0 && month == 2 && date == 29) {
                            break;
                        }
                        //student.setEnglish(String.valueOf(cell.getNumericCellValue()));
                    } else if (colIndex == 3) {

                        Double val = cell.getNumericCellValue();
                        str += " " + String.format("%.3f", val);
                        outputcol++;
                        outputElems++;

                        // if 365

                        // if 14
                        if (outputcol == 14) {
                            str += EOL;
                            outputcol = 0;
                        }

                        if (outputElems == 365) {
                            outputElems = 0;
                            outputcol = 0;
                            str += EOL;
                        }
                    }
                }
            }
            overallRow++;
        }
        String line2 = String.format("   %d   YEARS OF RECORD" + EOL, (endYr - startYr + 1));
        str = line2 + str;
        writer.print(str);
    } catch (Exception ioe) {
        ioe.printStackTrace();
    } finally {
        //writer.close();
    }
}