POI: Read from specific line and send to DB

0

Hello. I am working on a TCC in JAVA and one of its functions will be to read EXCEL files and send the data to the Database.

I'm starting small in JAVA and some things still confuse a lot, so I've researched a lot about it. The question is: How do I from the example below, I can start reading from line 5 of .xlsx and how should I export that data to the database?

I am 3 days searching and as I did not find anything specific, I am using StackOverflow ... Thanks in advance

public static void main(String[] args) {

    FileInputStream fisPlanilha = null;

    try {
        File file = new File("C:\Users\wi-li\Downloads\PrograminhasLerXlsx\xlsx\planilhas\planilhaDaAula.xlsx");
        fisPlanilha = new FileInputStream(file);

        //cria um workbook = planilha toda com todas as abas
        XSSFWorkbook workbook = new XSSFWorkbook(fisPlanilha);

        //recuperamos apenas a primeira aba ou primeira planilha
        XSSFSheet sheet = workbook.getSheetAt(0);

        //retorna todas as linhas da planilha 0 (aba 1)
        Iterator<Row> rowIterator = sheet.iterator();

        //varre todas as linhas da planilha 0
        while (rowIterator.hasNext()) {

            //recebe cada linha da planilha
            Row row = rowIterator.next();

            //pegamos todas as celulas desta linha
            Iterator<Cell> cellIterator = row.iterator();

            //varremos todas as celulas da linha atual
            while (cellIterator.hasNext()) {

                //criamos uma celula
                Cell cell = cellIterator.next();

                switch (cell.getCellType()) {

                    case Cell.CELL_TYPE_STRING:
                        System.out.println("TIPO STRING: " + cell.getStringCellValue());
                        break;

                    case Cell.CELL_TYPE_NUMERIC:
                        System.out.println("TIPO NUMERICO: " + cell.getNumericCellValue());
                        break;

                    case Cell.CELL_TYPE_FORMULA:
                        System.out.println("TIPO FORMULA: " + cell.getCellFormula());
                }

            }
        }

    } catch (FileNotFoundException ex) {
        Logger.getLogger(LendoXLSX.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(LendoXLSX.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        try {
            fisPlanilha.close();
        } catch (IOException ex) {
            Logger.getLogger(LendoXLSX.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

}
    
asked by anonymous 31.05.2017 / 18:13

0 answers