Files
PhpSpreadsheet/samples/Calculations/Engineering/COMPLEX.php
T
oleibman 641f86dc80 Eliminate Some "Mixed" Variables in Samples
A continuation of PR #3859. Change code that would be flagged if we were to run Phpstan at level 9 (we currently run level 8). I may or may not follow up with source code (454 level-9 problems remain for src), but there is no reason to avoid the effort for samples.

No changes are made to src.
2024-01-20 16:39:23 -08:00

42 lines
1003 B
PHP

<?php
use PhpOffice\PhpSpreadsheet\Spreadsheet;
require __DIR__ . '/../../Header.php';
$category = 'Engineering';
$functionName = 'COMPLEX';
$description = 'Converts real and imaginary coefficients into a complex number of the form x + yi or x + yj';
$helper->titles($category, $functionName, $description);
// Create new PhpSpreadsheet object
$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
// Add some data
$testData = [
[3, 4],
[3, 4, '"j"'],
[3.5, 4.75],
[0, 1],
[1, 0],
[0, -1],
[0, 2],
[2, 0],
];
$testDataCount = count($testData);
for ($row = 1; $row <= $testDataCount; ++$row) {
$worksheet->setCellValue('A' . $row, '=COMPLEX(' . implode(',', $testData[$row - 1]) . ')');
}
for ($row = 1; $row <= $testDataCount; ++$row) {
$helper->log(
"(A$row): Formula "
. $worksheet->getCell('A' . $row)->getValue()
. ' result is '
. $worksheet->getCell('A' . $row)->getCalculatedValue()
);
}