OK, I understand now.
You need to look at the shiftRows() method of the HSSFSheet class. This
method will actually 'remove' the row for you by shifting up all of the
rows below the one you are deleting. It does however have a wrinkle or
two so you may need to experiment with the indices you supply. To give
you some idea of how it works, I have put together this little bit of
code;
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet sheet = workbook.createSheet("First Sheet");
HSSFRow row = sheet.createRow(0);
HSSFCell cell = row.createCell((short)0);
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
cell.setCellValue("Test Cell 1");
row = sheet.createRow(1);
cell = row.createCell((short)0);
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
cell.setCellValue("Test Cell 2");
row = sheet.createRow(2);
cell = row.createCell((short)0);
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
cell.setCellValue("Test Cell 3");
sheet.removeRow(sheet.getRow((short)1));
sheet.shiftRows(2, 2, -1);
workbook.write(new FileOutputStream(outputFile));
Which uses deprecated methods I know but also illustrates that despite
removing row index 1, I need to supply the actual row number to the
shiftRows() method - 2 in this case.
--- On Wed, 7/30/08, Manav Khanna <[EMAIL PROTECTED]> wrote:
From: Manav Khanna <[EMAIL PROTECTED]>
Subject: Re: Removing rows from HSSFSheet
To: "POI Users List" <[email protected]>
Date: Wednesday, July 30, 2008, 11:53 PM
Before the sheet is generated via FileOutputStream these modifications
are done.
And when the sheet is generated the rows which were supposed to be deleted
are stil there, and if they had any cell data, that data is cleared though.
Total no. of rows remain same, with the removed rows appearing as blank
rows.
Anthony Andrews wrote:
>This may sound a silly question but when you say that the row is still
there what do you mean? Do you mean that when you remove the row, save the
workbook away and then open it again in Excel the row can still be seen or that
if you remove the row you can still read it in code?
>
>--- On Wed, 7/30/08, Manav Khanna <[EMAIL PROTECTED]> wrote:
>From: Manav Khanna <[EMAIL PROTECTED]>
>Subject: Removing rows from HSSFSheet
>To: [email protected]
>Date: Wednesday, July 30, 2008, 9:55 PM
>
>Hi
> I have to remove some rows(including blank) from an HSSFSheet.
> But some how the sheet.removeRow(row) api deletes the contents
> of the rows but does not actually delete the row.
>
> Any pointers how can it be done?
>
>Thanks
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]
>
>
>
>
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]