ManiMuthuPandi February 2016

Set cell background using column and row index

I am setting a cell value in phpexcel using below method setCellValueByColumnAndRow()

$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col,$xlsRow,$plan);

Now my requirment is to set background color for this.

I am not able to use this below method as I am aligned with rows and columns numbers.

 $objPHPExcel->getActiveSheet()->getStyle("A1")->getFill()
    ->setFillType(PHPExcel_Style_Fill::FILL_SOLID)
    ->getStartColor()->setRGB($color);

I am searching a way to provide cols and rows as (2,3) not like ('A1:E1')

Please suggest an alternative way to set background color using column and row numbers.

Answers


Jimish Gamit February 2016

You cannot style a row in PHPExcel, only a cell or a range of cells

$objPHPExcel->getActiveSheet()
    ->getStyle('A1:E1')
    ->getFill()
    ->setFillType(PHPExcel_Style_Fill::FILL_SOLID)
    ->getStartColor()
    ->setARGB('FF808080');

or

$objPHPExcel->getActiveSheet()
    ->getStyle('A1:E1')
    ->applyFromArray(
        array(
            'fill' => array(
                'type' => PHPExcel_Style_Fill::FILL_SOLID,
                'color' => array('rgb' => 'E05CC2')
            )
        )
    );

Will set the background fill style for cells A1 to E1

Post Status

Asked in February 2016
Viewed 3,440 times
Voted 12
Answered 1 times

Search




Leave an answer