}
protected HSSFSheet getExcelSheet() {
final int numberOfSheets = getExcelWorkbook().getNumberOfSheets();
if (numberOfSheets == 0) {
throw new StepExecutionException("This spreadsheet has no sheets", this);
}
HSSFSheet sheet = null;
if (fSheetName != null) {
sheet = getExcelWorkbook().getSheet(fSheetName);
if (sheet == null) {
throw new StepExecutionException("A sheet named '"+ fSheetName + "' was not found in the file.", this);
}
}
if (sheet == null && fSheetIndex != null) {
final int sheetIndex = Integer.parseInt(fSheetIndex);
if (sheetIndex < 0 || sheetIndex >= numberOfSheets) {
throw new StepExecutionException("Invalid sheet index: "+fSheetIndex + ". This workbook contains sheets with indexes from 0 to "+ (numberOfSheets-1) + ".", this);
}
sheet = getExcelWorkbook().getSheetAt(sheetIndex);
}
if (sheet == null) {
sheet = (HSSFSheet) getContext().get(KEY_CURRENT_SHEET);