How to delete [not clear] rows in a spreadsheet using Apache POI [workbook]?
The POI project consists of APIs for manipulating various file formats based upon Microsoft’s OLE 2 Compound Document format, and Office OpenXML format, using pure Java. In short, you can read and write MS Excel files using Java. In addition, you can read and write MS Word and MS PowerPoint files using Java. POI is your Java Excel solution (for Excel 97-2007). However, we have a complete API for porting other OLE 2 Compound Document formats and welcome others to participate.

When I remove a row from the spreadsheet using Apache POI the cell values in the row get clear and the row still exist with empty cells.

This is what I execute in the code HSSFSheet.removeRow(HSSFRow)

How can I completely remove the row from the worksheet [workbook]?

Please advise, thanks.

POI can be quite difficult to work with…

That being said…

I think the behavior that POI is doing is correct.

What happens when you delete a column in a normal Excel spread sheet?

In the version of Excel (2007) I have the row is deleted, but all the other rows below that row are moved up and 24 is now referred to as 23.

Best of Luck.

hooknc: Understood.

I am trying to use HSSFSheet.shiftRows(int startRow, int endRow, int n);

public void shiftRows(int startRow,
int endRow,
int n)

Shifts rows between startRow and endRow n number of rows. If you use a negative number, it will shift rows up. Code ensures that rows don't wrap around. Calls shiftRows(startRow, endRow, n, false, false);

Additionally shifts merged regions that are completely defined in these rows (ie. merged 2 cells on a row to be shifted).

Specified by:
    shiftRows in interface Sheet

    startRow - the row to start shifting
    endRow - the row to end shifting
    n - the number of rows to shift

So far no luck, I think I am close. Any hints will be appreciated.


I figured it out, this works HSSFSheet.shiftRows(int startRow, int endRow, int n);