You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1.4 KiB
44 lines
1.4 KiB
2 months ago
|
<?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) {
|
||
|
$helper->log(sprintf(
|
||
|
'%s and %d months is %d (%s)',
|
||
|
$worksheet->getCell('B' . $row)->getFormattedValue(),
|
||
|
$worksheet->getCell('C' . $row)->getFormattedValue(),
|
||
|
$worksheet->getCell('D' . $row)->getCalculatedValue(),
|
||
|
$worksheet->getCell('D' . $row)->getFormattedValue()
|
||
|
));
|
||
|
}
|