I'm using PHP spreadsheet class to successfully create an xlsx spreadsheet with several charts. The spreadsheet is written down to disk. After that I would like to export these charts from spreadsheet to separate .png files. Based on documentation I tried to use the following code:
$inputFileType = \PhpOffice\PhpSpreadsheet\IOFactory::identify($XLSXfilepath);
$reader = IOFactory::createReader($inputFileType);
$reader->setIncludeCharts(true);
$spreadsheet = $reader->load($XLSXfilepath, $reader::LOAD_WITH_CHARTS);
$nr = 1;
foreach ($spreadsheet->getWorksheetIterator() as $worksheet) {
$chartNames = $worksheet->getChartNames();
foreach ($chartNames as $chartName) {
$chart = $worksheet->getChartByName($chartName);
try{
//the following code results false:
$res = $chart->render('temp/chart'.$nr.'.png');
} catch(Exception $e){
//this doesn't happen, which means then no exception is thrown:
print $e->getMessage();
}
$nr++;
}
}
The problem is that $chart->render results false with any error message and - of course - no .png file is saved on disk. But no exception is thrown. I double-checked that I have full rights to save files to the selected location and of course, there is enough free space on disk... I also checked that foreach loop properly finds all charts, which are saved in the .xlsx file.
Is there any way to find out why the charts are not rendered to files?
source https://stackoverflow.com/questions/71369296/phpspreadsheet-how-to-save-charts-to-separate-png-files
No comments:
Post a Comment