Forum


Replies: 4   Views: 1269
Change values of multiple graphs in a template
Topic closed:
Please note this is an old forum thread. Information in this post may be out-to-date and/or erroneous.
Every phpdocx version includes new features and improvements. Previously unsupported features may have been added to newer releases, or past issues may have been corrected.
We encourage you to download the current phpdocx version and check the Documentation available.

Posted by admin  · 14-05-2021 - 12:38

Hello,

Without updating the version, please edit DocxUtilities.php and go to the replaceChartData method. In this method you can find the following lines:

$chartStructure = $excel->createXlsx('datos' . str_replace('rId', '', $idCharts[$idChart]) . '.xlsx', $charData);
$chartStructure->saveDocx('datos' . str_replace('rId', '', $idCharts[$idChart]) . '.xlsx');
rename('datos' . str_replace('rId', '', $idCharts[$idChart]) . '.xlsx.docx', 'datos' . str_replace('rId', '', $idCharts[$idChart]) . '.xlsx');

replace them by:

$chartStructure = $excel->createXlsx('datos' . str_replace('rId', '', $idCharts[$idChart]) . '.xlsx', $charData);
$chartStructure->saveDocx($this->getTempDir() . '/' . 'datos' . str_replace('rId', '', $idCharts[$idChart]) . '.xlsx');
rename($this->getTempDir() . '/datos' . str_replace('rId', '', $idCharts[$idChart]) . '.xlsx.docx', $this->getTempDir() . '/datos' . str_replace('rId', '', $idCharts[$idChart]) . '.xlsx');

In this same method you need to replace two other lines:

$zip->addFile('datos' . str_replace('rId', '', $idCharts[$idChart]) . '.xlsx', str_replace('../', 'word/', $chartTarget));

by:

$zip->addFile($this->getTempDir() . '/datos' . str_replace('rId', '', $idCharts[$idChart]) . '.xlsx', str_replace('../', 'word/', $chartTarget));

and:

foreach ($chartData as $idChart => $data) {
    unlink('datos' . str_replace('rId', '', $idCharts[$idChart]) . '.xlsx');
}

by:

foreach ($chartData as $idChart => $data) {
    unlink($this->getTempDir() . '/datos' . str_replace('rId', '', $idCharts[$idChart]) . '.xlsx');
}

The previous changes use the default temp dir to save the XLSX to be added instead of the current folder.

replaceChartData is being improved in the current testing branch to add new features.

Regards.