Hello,
Thanks for sending the requested information about the license you are using.
Please check your inbox. We have replied with all the needed information to use this option correctly, and with an update of the class.
Below you can read the same information sent by email:
With phpxlsx 4 (and also phpxlsx 3.5, phpxlsx 3, and phpxlsx 2.5), please apply the cellStyles using an array when adding cell contents with styles using addTable.
For example:
$xlsx = new CreateXlsx();
$cellStyles = array(
'type' => 'general',
'backgroundColor' => 'D9E1F2',
);
$contents = array(
array(
array(
'text' => '10',
['cellStyles' => $cellStyles],
),
array(
'text' => '50',
['cellStyles' => $cellStyles],
),
array(
'text' => '20',
['cellStyles' => $cellStyles],
),
),
array(
array(
'text' => '20',
['cellStyles' => $cellStyles],
),
array(
'text' => '25.5',
['cellStyles' => $cellStyles],
),
array(
'text' => '31',
['cellStyles' => $cellStyles],
),
),
);
$options = array(
'columnNames' => array(
array(
'text' => 'Values 1',
'bold' => true,
'color' => 'FFFFFF',
'cellStyles' => array(
'backgroundColor' => '4472C4',
),
),
array(
'text' => 'Values 2',
'bold' => true,
'color' => 'FFFFFF',
'cellStyles' => array(
'backgroundColor' => '4472C4',
),
),
array(
'text' => 'Values 3',
'bold' => true,
'color' => 'FFFFFF',
'cellStyles' => array(
'backgroundColor' => '4472C4',
),
),
),
);
$xlsx->addTable($contents, 'B3', array(), $options);
$xlsx->saveXlsx('output');
As you can check in this sample script, instead of:
array(
'text' => 'Cell content',
'cellStyles' => $cellStyles,
),
please use an array to set cellStyles:
array(
'text' => 'Cell content',
['cellStyles' => $cellStyles],
),
Using this code, everything will work as expected. Please note that this array must only be set in the $contents parameter of the addTable method, not in $options.
The next stable release of phpxlsx won't have this requirement/limitation/issue, and cell styles applied to cell contents using addTable will be applied as expected using:
array(
'text' => 'Cell content',
'cellStyles' => $cellStyles,
),
Regards.