how to delete rows in excel sheet

Topics: Developer Forum, User Forum
Jan 14, 2010 at 5:16 PM

Hello,

 I have a xls sheet from where I want to delete rows .

I have the following code .

<?php

include 'Classes/PHPExcel.php';
include 'Classes/PHPExcel/IOFactory.php';

include 'Classes/PHPExcel/Writer/Excel5.php';

$objReader = PHPExcel_IOFactory::createReader('Excel5');
$objPHPExcel = $objReader->load("MOM.xls");
$max = $objPHPExcel->getActiveSheet()->getHighestRow();

print "$max";
$max = $objPHPExcel->getSheetCount();
print "$max";

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

?>

But the function removeRow fails to delete any row. I do  not get any error also.Can any one tell where am I going wrong ?

Please guide me,

Regards,

Mithun

 

 

 

Jan 15, 2010 at 6:25 AM

Hello ,

I am using PHP version 5.3.0 and phpexcel version 1.7.2. Please it would be great if someone can point out where am I going wrong.

Regards,

Mithun

Coordinator
Jan 15, 2010 at 9:45 AM

Your code doesn't show that you are writing the changes back to the file: I assume you are doing this?

<?php

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);

?>