This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Other Open Source Projects and the fly likes Delete a row from an Excel sheet with Apache POI / HSSF? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "Delete a row from an Excel sheet with Apache POI / HSSF?" Watch "Delete a row from an Excel sheet with Apache POI / HSSF?" New topic
Author

Delete a row from an Excel sheet with Apache POI / HSSF?

Philippe Desrosiers
Ranch Hand

Joined: Mar 29, 2006
Posts: 138
Anyone know how I can remove a row from an Excl sheet using Apache POI / HSSF? I tried the HSSFSheet.removeRow() method, but that seems to only clear the contents of the row, not remove it from the sheet.

Arun Kumar
Ranch Hand

Joined: Oct 10, 2007
Posts: 30
removeRow takes org.apache.poi.ss.usermodel.Row object. Incase you are passing the right Row object, it does delete the Row. Other option is to create a new sheet excluding that row.
Philippe Desrosiers
Ranch Hand

Joined: Mar 29, 2006
Posts: 138
Arun Kumar wrote:removeRow takes org.apache.poi.ss.usermodel.Row object. Incase you are passing the right Row object, it does delete the Row. Other option is to create a new sheet excluding that row.


Thanks Arun. Maybe this is something specific to the particular Excel file I'm trying to use (although I have tried it on many files), or the way I iterate over the rows in the sheet, but the row is never deleted, only cleared.

Basically, I'm trying to go through the sheet, row by row, remove specific rows that don't meet certain criteria, then save the sheet under a new filename. Here's the code:



If anyone has tried this before, and succeeded, can you let me know how you did it?

thanks!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Delete a row from an Excel sheet with Apache POI / HSSF?
 
Similar Threads
Apache POI
regarding POI HSSF programming
java.lang.OutOfMemoryError using Apache POI.jar
how to fetch data from excel sheet and dump to Mysql database
Detect filter in excel sheet using Apache POI