PhpSpreadsheet/samples/Chart/34_Chart_update.php
oleibman 585409a949
Testing - Delete Temp Files When No Longer Needed (#1488)
No code changes. The tests in all of these scripts write to at least
one temporary file, which is then read and not used again. The file
should be deleted to avoid filling up the disk system.
2020-05-24 20:03:07 +09:00

41 lines
1.1 KiB
PHP

<?php
use PhpOffice\PhpSpreadsheet\Reader\Xlsx as XlsxReader;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx as XlsxWriter;
require __DIR__ . '/../Header.php';
// 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
$filename = $helper->getFilename(__FILE__);
$writer = new XlsxWriter($spreadsheet);
$writer->setIncludeCharts(true);
$callStartTime = microtime(true);
$writer->save($filename);
$helper->logWrite($writer, $filename, $callStartTime);