poi excel跳过第一行

ryhaxcpt  于 2021-08-25  发布在  Java
关注(0)|答案(1)|浏览(460)

我让poi excel读取、上传并保存到数据库中,但当我检查我的数据库时,excel解析数据库没有第一行。我试图改变代码,但它不工作,所以我把我的原始代码。请帮忙!

public static List<Product> excelToExcelEntity(InputStream inputStream) {
        try {
            Workbook wb = new XSSFWorkbook(inputStream);
            Sheet sheet = wb.getSheet(SHEET);
            Iterator<Row> rows = sheet.iterator();

            List<Product> entities = new ArrayList<Product>();

            int rowNumber = 0;
            while (rows.hasNext()) {
                Row currentRow = rows.next();

                if (rowNumber == 0) {
                    rowNumber++;
                    continue;
                }
                Iterator<Cell> cellsInRow = currentRow.iterator();
                Product excelEntity = new Product();
                DataFormatter formatter = new DataFormatter();
                int cellIdx = 0;

                while (cellsInRow.hasNext()) {
                    Cell currentCell = cellsInRow.next();
                switch:
               ---
                break;}
                    cellIdx++;
                }
                entities.add(excelEntity);
            }
            wb.close();
            return entities;
jhiyze9q

jhiyze9q1#

if (rowNumber == 0) {
    rowNumber++;
    continue;
}

删除/注解上面的块代码,在这里continue将跳过进一步的执行并返回到列表中的下一个元素,在您的情况下,它将跳过第一行。

相关问题