php - Append new row to excel file using phpExcel library -
i new php phpexcel
. want save post data existing excel sheet every time new row.
as searched on stackoverflow.com got reference of library phpexcel
.
i write down following code taking samples.
<?php /** include phpexcel */ require_once 'classes/phpexcel.php'; $objphpexcel = new phpexcel(); $objphpexcel->setactivesheetindex(0); $objphpexcel->getactivesheet()->setcellvalue('a'.$row, $_post['name']); $objphpexcel->getactivesheet()->setcellvalue('b'.$row, $_post['email']); $objphpexcel->getactivesheet()->setcellvalue('c'.$row, $_post['phone']); $objphpexcel->getactivesheet()->setcellvalue('d'.$row, $_post['city']); $objphpexcel->getactivesheet()->setcellvalue('e'.$row, $_post['kid1']); $objphpexcel->getactivesheet()->setcellvalue('f'.$row, $_post['kid2']); $objwriter = new phpexcel_writer_excel2007($objphpexcel); $objwriter->save('myfile.xlsx'); ?>
but problem facing don't have idea how append new row excel sheet every time posted data saved new row.
i know code saving file disk everytime single row, need append new row last excel sheet.
<?php /** include phpexcel */ require_once 'classes/phpexcel.php'; require_once 'classes/phpexcel/iofactory.php'; $objphpexcel = phpexcel_iofactory::load("myfile.xlsx"); $objphpexcel->setactivesheetindex(0); $row = $objphpexcel->getactivesheet()->gethighestrow()+1; //echo $row; $objphpexcel->getactivesheet()->setcellvalue('a'.$row, $_post['name']); $objphpexcel->getactivesheet()->setcellvalue('b'.$row, $_post['email']); $objphpexcel->getactivesheet()->setcellvalue('c'.$row, $_post['phone']); $objphpexcel->getactivesheet()->setcellvalue('d'.$row, $_post['city']); $objphpexcel->getactivesheet()->setcellvalue('e'.$row, $_post['kid1']); $objphpexcel->getactivesheet()->setcellvalue('f'.$row, $_post['kid2']); $objwriter = new phpexcel_writer_excel2007($objphpexcel); $objwriter->save('myfile.xlsx'); ?>
Comments
Post a Comment