SureshK
SureshK

Reputation: 123

How to apply styles in PHPExcel

I am working with PHPExcel & i want to give same style to some cells. I have tried below code, but it applies style to only A1.

$objPHPExcel->getActiveSheet()->getStyle('A1','B2','B3','c4')->getAlignment()->setIndent(1);

Upvotes: 0

Views: 1990

Answers (2)

Mark Baker
Mark Baker

Reputation: 212412

You can't simply provide a list of cells like 'A1','B2','B3','c4' because getStyle() only accepts a single argument; but that argument can be either a single cell (e.g. 'A1') or a range of cells like 'A1:C4'

so

$objPHPExcel->getActiveSheet()
    ->getStyle('A1:C4')
    ->getAlignment()->setIndent(1);

is perfectly acceptable, and actually recommended because it's a lot more efficient setting styles for a range than for individual cells

Upvotes: 3

Max Schindler
Max Schindler

Reputation: 380

Try this:

$scheduleSheet->getStyle("A1:C3")
    ->applyFromArray('fill' => [
            'type' => PHPExcel_Style_Fill::FILL_SOLID,
            'color' => ['rgb' => 'ACA5A5']
        ]
    );

Upvotes: 1

Related Questions