0

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);
SureshK
  • 123
  • 1
  • 4
  • 17

2 Answers2

3

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

Mark Baker
  • 209,507
  • 32
  • 346
  • 385
1

Try this:

$scheduleSheet->getStyle("A1:C3")
    ->applyFromArray('fill' => [
            'type' => PHPExcel_Style_Fill::FILL_SOLID,
            'color' => ['rgb' => 'ACA5A5']
        ]
    );
Linus Kleen
  • 33,871
  • 11
  • 91
  • 99
Max Schindler
  • 380
  • 2
  • 17