can someone tell me how to iterate and delete all the empty rows in excel file using apache poi? I am calling those 2 functions with row indexes that i wish to delete, but the second one (shift) is always giving me Minumum row index is 0 exceltion.
public static void removeRow(HSSFSheet sheet, int rowIndex) {
HSSFRow removingRow = sheet.getRow(rowIndex);
if (removingRow != null) {
sheet.removeRow(removingRow);
}
}
public static void shiftRow(HSSFSheet sheet, int rowIndex) {
int lastRowNum = sheet.getLastRowNum();
if (rowIndex >= 0 && rowIndex < lastRowNum) {
sheet.shiftRows(rowIndex+1, rowIndex+1, -1);
}
}
Thanks
The problem was in columns that were merged in the excel file.