Using an existing Spreadsheet with Graphs for PhpSpreadsheet

66 Views Asked by At

I want to use an existing Excel spreadsheet as a template for my report. If I use the following code to open the file and then output it

$spreadsheet = IOFactory::load( $template_file );

ob_end_clean();
// Set the headers to force a download of the Excel file
header( 'Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' );
header( 'Content-Disposition: attachment; filename="testing.xlsx"' );
header( 'Cache-Control: max-age=0' );

$writer = new Xlsx($spreadsheet);

ob_start();
$writer->save( 'php://output' );
exit;

the result always has errors. Checking those with Xcode, I get the following

Removed Part: Drawing shape.

Excel can repair the file, but the chart (which is very simple) gets removed every time I download the file.

How can I use an Excel file with charts as a template when using PhpSpreadsheet?

0

There are 0 best solutions below