Forum


Replies: 1   Views: 250
Cell formatting for replacevariablebytext
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 jeroen8087  · 02-02-2023 - 15:44

The method replaceVariableByText replaces a text cell with another value. It would be nice to format this cell afterwards. Example: when I set some numeric value in a variable field, the format of the cell should be set to numeric.

Please see the following example:

$value = 4.5;
$xlsx = new CreateXlsxFromTemplate("template.xlsx");

$xlsx->replaceVariableByText(["variable" => $value]);
// The cell value is now 4.5

// The following is not possible:
$xlsx->modifyVariableCell("variable", ["type" => "number"]);

I looked into the method getTemplateVariables. This gives me a list of variable names, but not their cell coordinates. If I have these coordinates, I can just use addCell on that coordinate.

Is there a way to accomplish this?