Reputation: 89
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 ?
Upvotes: 1
Views: 3038
Reputation: 640
$objPHPExcel = $objReader->load("FILE.xlsx");
$objWorksheet = $objPHPExcel->getActiveSheet();
Just open the file
Upvotes: 2
Reputation: 13347
In your current code you are creating a new PHPExcel() object each time. You need to load the existing, then insert a new row. See here for how: Adding a new row with PHPExcel?
Upvotes: 1