javaapache poi(第 2 部分)

java apache poi (part 2)

续。在

要跳过第一行:

while(rowIterator.hasNext()){

    row = (XSSFRow)rowIterator.next();

    if(row.getRowNum()==0) {
        continue;
    }

    List<String> record = new ArrayList<String>();
    Iterator<Cell> cellIterator = row.cellIterator();
    ...
    readFile();
}

添加rowIterator.next();在忽略第一个 row.So simple.Hope 的程序中的 While 循环上方,这对您有帮助。

 **rowIterator.next();**
            while (rowIterator.hasNext())
            {
                Row row = rowIterator.next();
                //For each row, iterate through all the columns
                Iterator<Cell> cellIterator = row.cellIterator();

                while (cellIterator.hasNext())
                {
                    Cell cell = cellIterator.next();
                    //Check the cell type and format accordingly
                    switch (cell.getCellType())
                    {
                        case Cell.CELL_TYPE_NUMERIC:
                            System.out.print(cell.getNumericCellValue() + "t");
                            break;
                        case Cell.CELL_TYPE_STRING:
                            System.out.print(cell.getStringCellValue() + "t");
                            break;
                    }
                }
                System.out.println("");
            }
            file.close();
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }