File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Philippe Desrosiers
Ranch Hand
Posts: 138
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 30
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 138
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic