Files
PhpSpreadsheet/samples/Calculations/DateTime/EDATE.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

49 lines
1.5 KiB
PHP

<?php
use PhpOffice\PhpSpreadsheet\Spreadsheet;
require __DIR__ . '/../../Header.php';
$category = 'Date/Time';
$functionName = 'EDATE';
$description = 'Returns the serial number that represents the date that is the indicated number of months before or after a specified date';
$helper->titles($category, $functionName, $description);
// Create new PhpSpreadsheet object
$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
$months = range(-12, 12);
$testDateCount = count($months);
for ($row = 1; $row <= $testDateCount; ++$row) {
$worksheet->setCellValue('A' . $row, '=DATE(2020,12,31)');
$worksheet->setCellValue('B' . $row, '=A' . $row);
$worksheet->setCellValue('C' . $row, $months[$row - 1]);
$worksheet->setCellValue('D' . $row, '=EDATE(B' . $row . ', C' . $row . ')');
}
$worksheet->getStyle('B1:B' . $testDateCount)
->getNumberFormat()
->setFormatCode('yyyy-mm-dd');
$worksheet->getStyle('D1:D' . $testDateCount)
->getNumberFormat()
->setFormatCode('yyyy-mm-dd');
// Test the formulae
for ($row = 1; $row <= $testDateCount; ++$row) {
/** @var null|bool|float|int|string */
$calc = $worksheet->getCell('D' . $row)->getCalculatedValue();
$helper->log(
$worksheet->getCell('B' . $row)->getFormattedValue()
. ' and '
. $worksheet->getCell('C' . $row)->getFormattedValue()
. ' months is '
. $worksheet->getCell('D' . $row)->getCalculatedValue()
. ' ('
. $worksheet->getCell('D' . $row)->getFormattedValue()
. ')'
);
}