mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-08-17 20:11:49 +00:00
2fac9ee2f7
* Stacked Alignment - Use Class Constant Rather than Literal PR #1580 defined constants for "stacked" alignment in cells. Using those constants outside of Style/Alignment was beyond the scope of the original PR, but I said I would get to it. This PR replaces all uses of literal -165, and appropriate uses of literal 255, with the named constants, and adds tests to make sure that the changed code is covered in the test suite.
44 lines
1.2 KiB
PHP
44 lines
1.2 KiB
PHP
<?php
|
|
|
|
use PhpOffice\PhpSpreadsheet\IOFactory;
|
|
use PhpOffice\PhpSpreadsheet\Shared\Date;
|
|
|
|
require __DIR__ . '/../Header.php';
|
|
|
|
$helper->log('Load from Xls template');
|
|
$reader = IOFactory::createReader('Xls');
|
|
$spreadsheet = $reader->load(__DIR__ . '/../templates/30templatebiff5.xls');
|
|
|
|
$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,
|
|
],
|
|
];
|
|
|
|
$spreadsheet->getActiveSheet()->setCellValue('D1', Date::PHPToExcel(time()));
|
|
|
|
$baseRow = 5;
|
|
foreach ($data as $r => $dataRow) {
|
|
$row = $baseRow + $r;
|
|
$spreadsheet->getActiveSheet()->insertNewRowBefore($row, 1);
|
|
|
|
$spreadsheet->getActiveSheet()->setCellValue('A' . $row, $r + 1)
|
|
->setCellValue('B' . $row, $dataRow['title'])
|
|
->setCellValue('C' . $row, $dataRow['price'])
|
|
->setCellValue('D' . $row, $dataRow['quantity'])
|
|
->setCellValue('E' . $row, '=C' . $row . '*D' . $row);
|
|
}
|
|
$spreadsheet->getActiveSheet()->removeRow($baseRow - 1, 1);
|
|
|
|
// Save
|
|
$helper->write($spreadsheet, __FILE__);
|