用于Excel的POI java阅读器不占用第一张表

时间:2016-09-02 05:40:39

标签: java excel apache-poi

我试图拍摄第一张纸并将其放入LinkedList中,但它不会占用第一张纸,从第一张开始,我的计数器从零开始。一直在尝试其他类型的东西,表0完全填满。

    public void leer_archivo(String ruta)throws IOException{


       FileInputStream file = new FileInputStream(new File (ruta));


       XSSFWorkbook workbook = new XSSFWorkbook(file); 

      for (int i = 0; i < 5; i++){
        System.out.println(i);
        XSSFSheet sheet = workbook.getSheetAt(i);

        Iterator<Row> rowIterator = sheet.iterator();
        Row row;

        while (rowIterator.hasNext()){
            row = rowIterator.next();

            Iterator<Cell> cellIterator = row.cellIterator();
            Cell celda;

            while (cellIterator.hasNext()){
                celda = cellIterator.next();

                switch(celda.getCellType()) {
                    case Cell.CELL_TYPE_NUMERIC:
                        if( HSSFDateUtil.isCellDateFormatted(celda) ){
                             System.out.println(celda.getDateCellValue());

        }else{

        //   System.out.println(celda.getNumericCellValue());
                //Cuando cae aqui repite los valores de la celda 

        }   

                 valorCelda = (int) celda.getNumericCellValue();
                 agregar_valor( valorCelda, i);

         break;


                case Cell.CELL_TYPE_STRING: 
                    nombreCelda = celda.getStringCellValue();
                    agregar_equipo(nombreCelda, i);
                    System.out.println(i + "hola");


        break;  

    }


    }   
}

workbook.close();

}

}

0 个答案:

没有答案