Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete contents of an Excel sheet in Java?

How to delete contents of an Excel sheet in an Excel workbook, using Java SE and Apache POI?

like image 613
Shumon Saha Avatar asked Dec 03 '22 07:12

Shumon Saha


1 Answers

As mentioned in previous comments

Sheet sheet = wb.getSheetAt(0);
for (Row row : sheet) {
   sheet.removeRow(row);
}

this code throwing ConcurrentModificationException to me. So, I have modified the code and it's working fine. Here is the code:

Sheet sheet = wb.getSheetAt(0);
Iterator<Row> rowIte =  sheet.iterator();
while(rowIte.hasNext()){
    rowIte.next();              
    rowIte.remove();
}
like image 110
Thirupathi Sriramoji Avatar answered Dec 06 '22 09:12

Thirupathi Sriramoji