I am using POI to manipulate an existing excel sheet.
I want to remove rows in the begining and add rows at the end. When I remove rows I move all rows after them up.
int numOfRows = sheet.getLastRowNum()+1;
int extraRows = numOfRows - maxAllowedRows;
for(int i=1;i<=extraRows;i++){ //i intialized with 1 to ignore header row.
sheet.removeRow(sheet.getRow(i));
}
sheet.shiftRows(extraRows+1,sheet.getLastRowNum(),-extraRows);
In current run of the program it works fine. But when the program runs again, as many rows as were removed and shifted in first run equal number of blank rows appear in the sheet at the bottom and any new row that I try to add at the bottom of the sheet gets added after these blank rows.
Is there a way to avoid appearance of blank rows after the remove and shift operation (i.e. Is there any way to actaully delete the rows?)