2016-08-31 16:15:54 +00:00
|
|
|
<?php
|
|
|
|
|
2017-05-17 22:02:17 +00:00
|
|
|
use PhpOffice\PhpSpreadsheet\IOFactory;
|
|
|
|
use PhpOffice\PhpSpreadsheet\Shared\Date;
|
|
|
|
|
2017-10-01 08:48:59 +00:00
|
|
|
require __DIR__ . '/../Header.php';
|
2016-08-31 16:15:54 +00:00
|
|
|
|
2016-10-06 11:49:41 +00:00
|
|
|
$helper->log('Load from Xls template');
|
2017-05-17 22:02:17 +00:00
|
|
|
$reader = IOFactory::createReader('Xls');
|
2017-10-01 08:48:59 +00:00
|
|
|
$spreadsheet = $reader->load(__DIR__ . '/../templates/30template.xls');
|
2016-08-31 16:15:54 +00:00
|
|
|
|
|
|
|
$helper->log('Add new data to the template');
|
|
|
|
$data = [['title' => 'Excel for dummies',
|
|
|
|
'price' => 17.99,
|
|
|
|
'quantity' => 2,
|
|
|
|
],
|
|
|
|
['title' => 'PHP for dummies',
|
|
|
|
'price' => 15.99,
|
|
|
|
'quantity' => 1,
|
|
|
|
],
|
|
|
|
['title' => 'Inside OOP',
|
|
|
|
'price' => 12.95,
|
|
|
|
'quantity' => 1,
|
|
|
|
],
|
|
|
|
];
|
|
|
|
|
2017-05-17 22:02:17 +00:00
|
|
|
$spreadsheet->getActiveSheet()->setCellValue('D1', Date::PHPToExcel(time()));
|
2016-08-31 16:15:54 +00:00
|
|
|
|
|
|
|
$baseRow = 5;
|
|
|
|
foreach ($data as $r => $dataRow) {
|
|
|
|
$row = $baseRow + $r;
|
|
|
|
$spreadsheet->getActiveSheet()->insertNewRowBefore($row, 1);
|
|
|
|
|
|
|
|
$spreadsheet->getActiveSheet()->setCellValue('A' . $row, $r + 1)
|
2018-01-28 06:59:38 +00:00
|
|
|
->setCellValue('B' . $row, $dataRow['title'])
|
|
|
|
->setCellValue('C' . $row, $dataRow['price'])
|
|
|
|
->setCellValue('D' . $row, $dataRow['quantity'])
|
|
|
|
->setCellValue('E' . $row, '=C' . $row . '*D' . $row);
|
2016-08-31 16:15:54 +00:00
|
|
|
}
|
|
|
|
$spreadsheet->getActiveSheet()->removeRow($baseRow - 1, 1);
|
|
|
|
|
|
|
|
// Save
|
|
|
|
$helper->write($spreadsheet, __FILE__);
|