删除不在phpexcel中的行

时间:2014-03-03 06:55:21

标签: php codeigniter phpexcel

如何删除由 phpexcel 生成的Excel工作表行。

我试过这个

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

从第二行开始删除两行。但似乎没有用......

1 个答案:

答案 0 :(得分:1)

您需要将更改写回文件,请参阅示例

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