Forum


Replies: 12   Views: 3344
Existing chart and merged documents
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 nbiz  · 10-04-2018 - 12:32

Hello,

I have several templates optimize with optimizeTemplate();

In these templates I have charts which I need to replace/fullfil with values.

After all that the templates are merged to create one document

$Docx = new CreateDocxFromTemplate('../Template/Optimize/Template.docx');
$Values = array(
    // Values
);

$Docx->replaceVariableByText($Values, array('raw' => true));

array_push($DocsToMerge, $Docx->createDocx());

How can I replace/add values to the existing charts? 

Thanks

Posted by nbiz  · 10-04-2018 - 16:25

Heĺlo.

I saw this function but what do I need to set for source and target in my case?

Maybe a little example? ☺

Thanks for yor help

Posted by admin  · 10-04-2018 - 17:00

Hello,

You can find an example on the same API page and all options explained. From this page:

source: Path to the docx.

target: Path to the resulting docx.

You just need to set the template with the DOCX to be changed as source, the output DOCX as target and the last option (data) is an array with the new data. We recommend you to check the example available on the API page, that is the same than the included in the package (exmaples folder).

Regards.

Posted by nbiz  · 10-04-2018 - 18:28

So it's not possible to modify the chart within the stream from CreateDocxFromTemplate(),  without creating a new document ? 

Posted by admin  · 11-04-2018 - 06:35

Hello,

You need to create the DOCX to be able to use replaceChartData. The current version of this method only works with DOCX files.

Regards.

Posted by nbiz  · 11-04-2018 - 07:25

Hello. 

It works well if I'm using createDocxAndDownload() after replacing chart data.

But when I'm using MultiMerge() I got this error

Warning: rename(datos9.xlsx.docx,datos9.xlsx): No such file or directory in /Project/PHPDocx/classes/DocxUtilities.inc on line 4078

Warning: unlink(datos9.xlsx): No such file or directory in /Project/PHPDocx/classes/DocxUtilities.inc on line 4083

 

Any ideas?

Thanks

Posted by nbiz  · 11-04-2018 - 08:13

It works when I remove the display error but will this cause a problem when generating my document? 

Posted by admin  · 11-04-2018 - 11:01

Hello,

We're unable to replicate your issue. We have tested it using MultiMerge and then replaceChartData with the DOCX output and it works perfectly.

Maybe you are mixing streams and DOCX files when generating the documents? or there's some missing rw access?, anyway, we recommend you to open the output you get to know if the chart data is replaced correctly.

Regards.

Posted by nbiz  · 11-04-2018 - 14:43

I resolve it thanks.

I have an other question . In my template I have a chart with 4 bars and sometimes the chart will only have 3 bars .

Is it possible to remove the last bar with replacechartdata()?

Posted by admin  · 11-04-2018 - 16:31

Hello,

replaceChartData replaces all data of a chart, but it doesn't allow to remove specific values such as the last bar, you need to replace the full data.

Regards.

Posted by nbiz  · 11-04-2018 - 17:23

Hello,

And how can I do that?

Posted by admin  · 12-04-2018 - 06:15

Hello,

Sorry but there's no method or option to remove specific values of a chart. We move the request to the dev team to consider adding support in a future release of phpdocx.

Regards.