1

I work with PHPExcel, and I want to remove (copletlly delete a row).

I currently use $objPHPExcel->getActiveSheet()->removeRow($i); which does empty the cells, but I want to completlly remove the rows.

I run a function that uses this code line, and right after it I check for the last row with content (using $objPHPExcel->setActiveSheetIndex(0)->getHighestRow(); - and I get the last row as if nothing wasn't deleted.

(Cells are empty tough... )

Imnotapotato
  • 5,308
  • 13
  • 80
  • 147
  • `$objPHPExcel->getActiveSheet()->removeRow($i);` should remove the row, shuffling all rows below up a step, although it does leave an empty row at the bottom of the worksheet..... it should not simply empty the cells, and I can't replicate a situation where it does this unless you are just calling it against the last row in the worksheet – Mark Baker Sep 08 '15 at 11:26
  • @MarkBaker are you 100% sure? – Imnotapotato Sep 08 '15 at 11:31
  • I have yet to see a case where it does not work as I've outlined above.... if you can present me with a working example that demonstrates otherwise, then I may be convinced that there's a bug which needs addressing.... but unless I see that evidence, I can only go on the results of my own tests – Mark Baker Sep 08 '15 at 11:57
  • 1
    But a call to `getHighestRow()` will not change, no matter how many rows you add or delete.... this value is read from the spreadsheet file on load, and will not then change – Mark Baker Sep 08 '15 at 12:06
  • 1
    If you want an accurate row count, then you have the `getHighestDataRow()` method, which counts dynamically when executed – Mark Baker Sep 08 '15 at 12:07
  • And this my friend, solved my problem! Thanks a lot for your help! :D – Imnotapotato Sep 08 '15 at 12:16
  • 1
    @MarkBaker Why don't you include some way to avoid the rows that have `NULL` or `Blank` in all columns? Like we can set `$cellIterator->setIterateOnlyExistingCells(False);` to avoid taking the whole column that is `NULL` or `Blank` ! – edam Sep 22 '15 at 05:41

0 Answers0