Search code examples
javaexcelspringimportapache-poi

How to read data from an excel file with header in java/spring


Excel file

I have this excel file. How to create a request in java/spring to read data from that file?

The problem i encounter is with the first two rows. I cant fetch data from excel for those. I don't know how to do this in apache POI.


Solution

  • So, the solution was this:

    String supplierName = null;
    
        // GET Supplier name
        for (int r = 0; r <= rows; r++) {
            XSSFRow row = sheet.getRow(r);
            if (r == 2) {
                break;
            }
            for (int c = 0; c < cols; c++) {
                if (r == 1) {
                    XSSFCell cell = row.getCell(c);
                    supplierName = cell.getStringCellValue();
                    break;
                }
            }
        }