PhpSpreadsheet: 32_Chart_read_write.php corrupted Excel 2013 file wth chart "xl/drawings/drawing1.xml"

This is:

- [x] a bug report
- [ ] a feature request
- [ ] **not** a usage question (ask them on https://stackoverflow.com/questions/tagged/phpspreadsheet or https://gitter.im/PHPOffice/PhpSpreadsheet)

I try to copy .xlsx file with chart and insert data to this file for this chart. Tried different ways and still when file is saved, I can’t open it successfully because it’s corrupted. How can I fix it?

What is the expected behavior?

Successfully save and open new .xlsx file with my data and chart

What is the current behavior?

The error that Component “xl/drawings/drawing1.xml” is deleted. Don’t understand why my chart became drawing.

What are the steps to reproduce?

I have tried to reproduce the process with the help of ready sample. Sample/32_Chart_read_write.php

Even with this sample, I can’t save not corrupted file with chart.

All code I have from "32_Chart_read_write.php" sample and used 2 my test.xlsx files that contain some date and 1 chart, 

Which versions of PhpSpreadsheet and PHP are affected?

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 24 (3 by maintainers)

Commits related to this issue

Most upvoted comments

I can confirm that charts generation seems to be broken. In my case, simply doing this gets a corrupted Xlsx file. If I force open it, the chart is gone.

$reader = IOFactory::createReader('Xlsx');
$reader->setIncludeCharts(true);
$spreadsheet = $reader->load('file_with_a_chart.xlsx');

$writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
$writer->setIncludeCharts(true);
$writer->save('test.xlsx');

I have no ideas at the moment. The module where this problem lies is particularly daunting. I am working on it for a different reason right now. My hope is that that work will give greater insight to addressing this. At any rate, I haven’t given up on it.