2021-01-29

XSSFWorkbook.getSheet() returns null

I am at the end of my wits. I am using XSSFWorkbook.getSheet(name) - but it returns null, and cannot figure out why. May be someone has run into it and has found solution.

    File file = new File(EXCEL_URL_REDIRECT_LIST_FILE_PATH);

    try (FileInputStream fis = new FileInputStream(file); XSSFWorkbook wb = new XSSFWorkbook(fis)) {
        String excelSheetName = "Sheet 1";
        int numSheets = wb.getNumberOfSheets();
        System.out.println("num sheets: " + numSheets);
        System.out.println(wb.getSheetName(0));

        XSSFSheet sheet = wb.getSheet(excelSheetName);
        .
        .
        .
     } catch (IOException e) {
     }

The console shows:

 num sheets: 1
 Sheet 1

But the wb.getSheet(excelSheetName) returns null.

What can be possible reasons?

Thanks.



from Recent Questions - Stack Overflow https://ift.tt/3pGd6mV
https://ift.tt/eA8V8J

No comments:

Post a Comment