How can I add a new row to an existing .xls file using PHPExcel?
Do I have to calculate the number of rows that already exist?
If so, how can I do that for a
The example above only adds a blank row. The example below adds data coming from a form.
getActiveSheet();
//add the new row
$num_rows = $objPHPExcel->getActiveSheet()->getHighestRow();
$objWorksheet->insertNewRowBefore($num_rows + 1, 1);
$name = isset($_POST['name']) ? $_POST['name'] : '';
if($submit){
//SAVING THE NEW ROW - on the last position in the table
$objWorksheet->setCellValueByColumnAndRow(0,$num_rows+1,$name);
}
//display the table
echo ''."\n";
echo '
Company Name
'."\n";
echo ''."\n";
foreach ($objWorksheet->getRowIterator() as $row) {
echo ''."\n";
$cellIterator = $row->getCellIterator();
$cellIterator->setIterateOnlyExistingCells(false);
foreach ($cellIterator as $cell) {
echo ''.$cell->getValue().' '."\n";
}
echo ' '."\n";
}
echo ''."\n";
echo '
'."\n";
?>