We are experiencing a strange bug regarding reading of Excel sheets via Apache Poi. We are using version 5.0.
This code previously worked, however it has now stopped working on all of our production environments. It still works when testing locally so this is proving quite difficult to debug.
The issue is that we are getting null sheet names returned, so are unable to correctly load the required sheet.
try (XSSFWorkbook wb = new XSSFWorkbook(new FileInputStream(venueListFile))) {
LOGGER.info("Found {} sheets", wb.getNumberOfSheets());
// First setup venues
Sheet venueSetUpSheet = wb.getSheet("Store Set Up");
List<String> sheetNames = new ArrayList<>();
for (Iterator<Sheet> it = wb.sheetIterator(); it.hasNext(); ) {
sheetNames.add(it.next().getSheetName());
}
if (venueSetUpSheet == null) {
LOGGER.warn("Sheet 'Store Set Up' not found, available sheets: '" + String.join("','", sheetNames) + "'");
} else {
LOGGER.info("Found sheets: " + String.join("','", sheetNames) + "'");
Locally this returns:
Found 5 sheets
Found sheets: Store Set Up','Store Open Hours','Staff Setup','TV Configurations','Sheet3'
In production for the same Excel file it returns:
Found 5 sheets
Sheet 'Store Set Up' not found, available sheets: 'null','null','null','null','null'
It seems the file is read, and we have tested that the uploaded file on the server isn't corrupted. Is anyone aware of a known issue with Poi which would result in null sheet names?