Files
PhpSpreadsheet/samples/Chart/34_Chart_update.php
T
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

37 lines
1.0 KiB
PHP

<?php
use PhpOffice\PhpSpreadsheet\Reader\Xlsx as XlsxReader;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx as XlsxWriter;
require __DIR__ . '/../Header.php';
/** @var PhpOffice\PhpSpreadsheet\Helper\Sample $helper */
// Create temporary file that will be read
$sampleSpreadsheet = require __DIR__ . '/../templates/chartSpreadsheet.php';
$filename = $helper->getTemporaryFilename();
$writer = new XlsxWriter($sampleSpreadsheet);
$writer->setIncludeCharts(true);
$writer->save($filename);
$helper->log('Load from Xlsx file');
$reader = new XlsxReader();
$reader->setIncludeCharts(true);
$spreadsheet = $reader->load($filename);
unlink($filename);
$helper->log('Update cell data values that are displayed in the chart');
$worksheet = $spreadsheet->getActiveSheet();
$worksheet->fromArray(
[
[50 - 12, 50 - 15, 50 - 21],
[50 - 56, 50 - 73, 50 - 86],
[50 - 52, 50 - 61, 50 - 69],
[50 - 30, 50 - 32, 50],
],
null,
'B2'
);
// Save Excel 2007 file
$helper->write($spreadsheet, __FILE__, ['Xlsx'], true);