When using the HSSF library when I print the current sheet name it prints the correct one. If I then get the cell value of a known cell in that sheet it will return the value of the cell in the next sheet along. How I get the sheet: private static Sheet getSheet(Workbook wb, String sheetName){ Sheet s = null; int numberOfSheets = workbook.getNumberOfSheets(); for (int i = 0; i < numberOfSheets; i++) { s = wb.getSheet(sheetName); if( s.getSheetName().equals(sheetName)){ return s; } } return s; } How I get the cell value: private static double getCellValue(Cell cell) { switch (cell.getCellType()) { case Cell.CELL_TYPE_NUMERIC: return cell.getNumericCellValue(); case Cell.CELL_TYPE_BLANK: return 0; } return 0; } double DOLabour = getCellValue(s.getRow(16).getCell(4));
Please add also your example sheet
Created attachment 33925 [details] Workbook
Won't the logic of your sheet selection loop mean that if the name doesn't match, the last sheet will always be returned + used? Could that actually be the cause of your issue? If not, any chance you could turn your test code into a junit unit test that we can use with your attached file to investigate more?
I have stepped through the code and if I am looking for the "PP1" sheet the function will return the "PP1" sheet and it will print this out using s.getSheetName(). When I then get the cell value using: How I get the cell value: private static double getCellValue(Cell cell) { switch (cell.getCellType()) { case Cell.CELL_TYPE_NUMERIC: return cell.getNumericCellValue(); case Cell.CELL_TYPE_BLANK: return 0; } return 0; } double DOLabour = getCellValue(s.getRow(16).getCell(4)) It will actually return the value of the "Application" sheet not the "PP1" sheet. I have also noticed that when I loop through the sheets the first sheet is called "Module1" not "PP1".
Have you had any further developments with this bug?
(In reply to cbradford from comment #5) > Have you had any further developments with this bug? I had a quick try on this and can only confirm the bug. Althougn the bound name is correct, I suspect that the vba sheet is causing an error with the sheet references ... but maybe someone else with a deeper knowledge of hssf can jump in?