mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-08-17 21:51:34 +00:00
ecbd702628
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.
28 lines
978 B
PHP
28 lines
978 B
PHP
<?php
|
|
|
|
use PhpOffice\PhpSpreadsheet\IOFactory;
|
|
use PhpOffice\PhpSpreadsheet\Writer\Html as HtmlWriter;
|
|
|
|
require __DIR__ . '/../Header.php';
|
|
/** @var PhpOffice\PhpSpreadsheet\Helper\Sample $helper */
|
|
$inputFileName = 'TableFormat.xlsx';
|
|
$inputFilePath = __DIR__ . '/../templates/' . $inputFileName;
|
|
|
|
$codePath = $helper->isCli() ? ('samples/templates/' . $inputFileName) : ('<code>' . 'samples/templates/' . $inputFileName . '</code>');
|
|
$helper->log('Read ' . $codePath);
|
|
$reader = IOFactory::createReader('Xlsx');
|
|
$reader->setReadDataOnly(false);
|
|
$spreadsheet = $reader->load($inputFilePath);
|
|
$helper->log('Enable table formatting output');
|
|
$helper->log('Enable conditional formatting output');
|
|
|
|
function writerCallback(HtmlWriter $writer): void
|
|
{
|
|
$writer->setPreCalculateFormulas(true);
|
|
$writer->setTableFormats(true);
|
|
$writer->setConditionalFormatting(true);
|
|
}
|
|
|
|
// Save
|
|
$helper->write($spreadsheet, __FILE__, ['Html'], false, writerCallback: writerCallback(...));
|