user1818079 user1818079 - 1 year ago 110
PHP Question

Append new row to Excel file with PHPExcel

I have this code

$objPHPExcel = new PHPExcel();
$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);


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 Source
$objPHPExcel = $objReader->load("FILE.xlsx");
$objWorksheet = $objPHPExcel->getActiveSheet();

Just open the file

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download