I\'ve faced with a problem. I don\'t know how to delete row without leaving afterwords empty row.
I am using Apache-POI 3.9 and I am getting error using next code :<
Try this code, it should work:
for(int i = 0; i < sheet.getLastRowNum(); i++)
{
row = sheet.getRow(i);
if(patternt.equals(getCurrentString(row)))
{
data.add(getDataFromRow(row));
// sheet.removeRow(row); NO NEED FOR THIS LINE
sheet.shiftRows(row.getRowNum() + 1, sheet.getLastRowNum() + 1, -1);
i--;
}
}
You need to decrease i
by one every time you delete one row. And get the last row number again by using getLastRowNum()
.