Files
oleibman ecbd702628 Phpstan and Samples
Phpstan hasn't identified any errors in Samples in a long time. But, as it turns out, one particular error is suppressed:
```
Variable $helper might not be defined.
```
This error would be generated by almost all samples, and the errors that it suppresses will become problematic if we move to Level 10. We are not yet committed to doing that, but it is pretty easy to write a script to change the samples so that error no longer happens, and there isn't really any reason to delay doing so. The results of that script constitute this PR.
2025-04-05 13:54:20 -07:00

30 lines
753 B
PHP

<?php
use PhpOffice\PhpSpreadsheet\Spreadsheet;
require __DIR__ . '/../Header.php';
/** @var PhpOffice\PhpSpreadsheet\Helper\Sample $helper */
$category = 'Date/Time';
$functionName = 'TODAY';
$description = 'Returns the serial number of the current date';
$helper->titles($category, $functionName, $description);
// Create new PhpSpreadsheet object
$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
$worksheet->setCellValue('A1', '=TODAY()');
$worksheet->getStyle('A1')
->getNumberFormat()
->setFormatCode('yyyy-mm-dd');
// Test the formulae
$helper->log(
'Today is '
. $worksheet->getCell('A1')->getCalculatedValueString()
. ' ('
. $worksheet->getCell('A1')->getFormattedValue()
. ')'
);