-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Stacked Alignment - Use Class Constant Rather than Literal (#1716)
* 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.
- Loading branch information
Showing
8 changed files
with
95 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?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__); |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters