Question

How to delete rows of excel sheet generated by phpexcel.

I have tried this

$sheet->getActiveSheet()->removeRow(2,2);

to delete two rows starting from second row. but seems not working...

Was it helpful?

Solution

you are need to writing the changes back to the file , see example

http://phpexcel.codeplex.com/discussions/80845

error_reporting(E_ALL);
set_time_limit(0);

/** Include path **/
set_include_path(get_include_path() . PATH_SEPARATOR . 'Classes/');

/** PHPExcel_IOFactory */
include 'PHPExcel/IOFactory.php';


$fileType = 'Excel5';
$fileName = 'deleteRowTest.xls';


$objPHPExcel = PHPExcel_IOFactory::load($fileName);


$objPHPExcel->getActiveSheet()->removeRow(2,2);


$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, $fileType);
$objWriter->save($fileName);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top