Forum


Replies: 4   Views: 42
Cellstyles display issue using addtable

Posted by Elisee9571  · 28-02-2025 - 09:27

$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);

        $fileName = Uuid::v7() . '.xlsx';
        $file = $this->getParameter('documents_dir') . '/' . $fileName;

        $xlsx->saveXlsx($file);

The issue i'm facing is related to CellStyles, everything that's related to the Contents CellStyles doesn't work. It's not displaying. More specifically, everything is working besides that, which means everything in the variable $options is working perfectly. The parameter cellStyles in the variable $contents isn't displaying.