Forum


Replies: 1   Views: 242
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?

Posted by admin  · 03-02-2023 - 12:58

Hello,

The replaceVariableByText method only replaces placeholders, but it doesn't allow setting new styles. A method that need to be developed will support this task.

Regarding the other question, there's no direct method to find the cell position of a specific content. But you can use getCellPositions to return all cell positions in the active sheet and then iterate the array returned by this method with getCell to get that information. getCell returns an array with the following information:

* @return array|null
     *      'function' (string)
     *      'sharedString' (string)
     *      'type' (string)
     *      'value' (string)

Regards.