user1818079 user1818079 - 5 months ago 29
PHP Question

Append new row to Excel file with PHPExcel

I have this code

$objPHPExcel = new PHPExcel();
$objPHPExcel->setActiveSheetIndex(0);
$LastRow = $objPHPExcel->setActiveSheetIndex(0)->getHighestRow();
$row = $LastRow + 1;

$objPHPExcel->getActiveSheet()->SetCellValue('A'.$row, $_POST['name']);
$objPHPExcel->getActiveSheet()->SetCellValue('B'.$row, $_POST['email'] );
$objPHPExcel->getActiveSheet()->SetCellValue('C'.$row, $_POST['tel']);
$objPHPExcel->getActiveSheet()->SetCellValue('D'.$row, $_POST['adresss']);

$objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel);

$objWriter->save('files\Clientes.xlsx');


The problem in here is the always create a new .xlsx file or erase the others rows that are in Excel File, i need Add a new row...
Any ideas ?

Answer
$objPHPExcel = $objReader->load("FILE.xlsx");
$objWorksheet = $objPHPExcel->getActiveSheet();

Just open the file