Forum


Replies: 2   Views: 438
Function calculation
Topic closed:
Please note this is an old forum thread. Information in this post may be out-to-date and/or erroneous.
Every phpxlsx 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 phpxlsx version and check the Documentation available.

Posted by KaiVoigt  · 14-10-2022 - 07:11

I created a simple Excel sheet which sums up 2 values.

Cell A1 contains a placeholder $val1$

Cell A2 contains a fixed number. for example 2

Cell A3 sums up Cell A1 and A2. 

$xlsxStructure = new XlsxStructure();
$xlsxStructure->parseXlsx($datasource);

$xlsx = new CreateXlsxFromTemplate($xlsxStructure);
$xlsx->replaceVariableText(array('val1' => 6));

$xlsx->saveXlsx($newXlsxFile);

After using the above code, the calculated value still shows the value 2 instead of 8.

Currently you need to manually click into the cell to update it.

I fixed this issue locally for now by adding attributes (fullCalcOnLoad & forceFullCalc) to the calcPr node in the workbook dom. this way the functions get evaluated on workbook load.

Unfortunately this way all functions get recalculated every single time the workbook is loaded. Instead all functions should be reevaluated on saving. 

Posted by admin  · 14-10-2022 - 08:19

Hello,

The current stable version of phpxlsx doesn't include a method to update function or calculated values automatically. It's a work in progress.

Regards.

Posted by KaiVoigt  · 14-10-2022 - 11:20

Alright, thanks for the info. Then I will stay with my current solution by adding the attributes to the calcPr node for now.