34_Chart_update.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. use PhpOffice\PhpSpreadsheet\IOFactory;
  3. use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
  4. require __DIR__ . '/../Header.php';
  5. // Create temporary file that will be read
  6. $sampleSpreadsheet = require __DIR__ . '/../templates/chartSpreadsheet.php';
  7. $filename = $helper->getTemporaryFilename();
  8. $writer = new Xlsx($sampleSpreadsheet);
  9. $writer->save($filename);
  10. $helper->log('Load from Xlsx file');
  11. $reader = IOFactory::createReader('Xlsx');
  12. $reader->setIncludeCharts(true);
  13. $spreadsheet = $reader->load($filename);
  14. $helper->log('Update cell data values that are displayed in the chart');
  15. $worksheet = $spreadsheet->getActiveSheet();
  16. $worksheet->fromArray(
  17. [
  18. [50 - 12, 50 - 15, 50 - 21],
  19. [50 - 56, 50 - 73, 50 - 86],
  20. [50 - 52, 50 - 61, 50 - 69],
  21. [50 - 30, 50 - 32, 50],
  22. ],
  23. null,
  24. 'B2'
  25. );
  26. // Save Excel 2007 file
  27. $filename = $helper->getFilename(__FILE__);
  28. $writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
  29. $writer->setIncludeCharts(true);
  30. $callStartTime = microtime(true);
  31. $writer->save($filename);
  32. $helper->logWrite($writer, $filename, $callStartTime);