Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHPExcel: How to get style from a row or range of cells and apply to another

Tags:

php

phpexcel

I'm trying to get the style of a row e.g. ("A3:V3"), pass it to an array, and then use that array with the applyFromArray(); function.

Here is what i tried:

$objPHPExcel = $objReader->load($inputFileName);
$sheet = $objPHPExcel->getActiveSheet();
$style = $sheet->getStyle("A3:V3");
$sheet->getStyle("A$totalRows:V$totalRows")->applyFromArray($style);

This throws the error 'Invalid style array passed.'

Is there any workaround for this?

like image 656
Peter Esenwa Avatar asked Jul 08 '16 13:07

Peter Esenwa


1 Answers

I found this in the docs - "If you want to copy the ruleset to other cells, you can duplicate the style object"

$objPHPExcel->getActiveSheet()->duplicateStyle($objPHPExcel->getActiveSheet()->getStyle('B2'), 'B3:B7');

So i didn't have to do this anymore. Should have just searched a little more.

like image 67
Peter Esenwa Avatar answered Sep 25 '22 01:09

Peter Esenwa