A
A
Aigul_per2015-12-07 15:49:32
PHP
Aigul_per, 2015-12-07 15:49:32

phpexcel. How to add a template?

Filling out an excel template. It is necessary to write down the line after the last filled one. But the data is entered in line 6. It turns out that i=6, although there are about 200 data in the table. How to do it right?

require_once 'PHPExcel.php';
$objPHPExcel = new PHPExcel();
$objReader = PHPExcel_IOFactory::createReader('Excel2007');
$objPHPExcel = $objReader->load('files/client.xlsx');
foreach ($objPHPExcel->getWorksheetIterator() as $worksheet) {
  $i=0;
do{
$row=$worksheet->getCellByColumnAndRow($i,$i+1);
$i++;
}while($row!='');
};
echo $i;
$ad_name = 'АД';
        $objPHPExcel->getActiveSheet()->setCellValue('A'.$i, $name);
    $objPHPExcel->getActiveSheet()->setCellValue('B'.$i, $phone);
    $objPHPExcel->getActiveSheet()->setCellValue('C'.$i, $mail);
    $objPHPExcel->getActiveSheet()->setCellValue('D'.$i, $input);
    $objPHPExcel->getActiveSheet()->setCellValue('E'.$i, $agent);
    $objPHPExcel->getActiveSheet()->setCellValue('F'.$i, $ad_name);
    $objPHPExcel->getActiveSheet()->setCellValue('G'.$i, ($i + 1));
    $objPHPExcel->getActiveSheet()->setCellValue('H'.$i, $date);
    $objPHPExcel->getActiveSheet()->setCellValue('I'.$i, $srok);
  
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, "Excel2007");
$excelFileName = "file.xlsx";
$excelFile = 'files/' . $excelFileName;
$objWriter->save($excelFile);

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Aigul_per, 2015-12-09
@Aigul_per

Did it like this:

$i=0;
do{
$row=$sheet->getCellByColumnAndRow('A', $i);
$i++;
}while($row!='');

Still not. How to do it right?

A
Alexander, 2016-11-01
@Intdev

I suspect that is no longer relevant, but this is how it should work:
$sheet->getCellByColumnAndRow(0, $i);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question