best way to apply same style to multiple cells

Topics: Developer Forum, User Forum
Mar 23, 2011 at 3:02 PM

hi

i have few styles defined which i will need to apply to specific cells on a worksheet. these cells are all around the worksheet and are not ranges, so the styles will need to be applied on each cell individually.

i already tried with applyFromArray, i defined all my styles in arrays and apply them on each cell i needed.

but, can somebody please tell me if there is another faster way to do this since i have tens of thousands of records to write and now it takes a long time?

thanks

Apr 6, 2011 at 7:57 PM

Try to dig into this code:

$objPHPExcel->getDefaultStyle()->getFont()->setName('Arial');
$objPHPExcel->getDefaultStyle()->getFont()->setSize(8);

 

Apr 6, 2011 at 8:06 PM

Or shorter:

$objPHPExcel->getDefaultStyle()->getFont()->setName('Arial')->setSize(8);


Coordinator
Apr 7, 2011 at 11:33 PM

Or apply the style to a row or column, or a range of cells.

Try something like:

$objPHPExcel->getActiveSheet()->getStyle('B')->getFont()->getColor()->setARGB(PHPExcel_Style_Color::COLOR_RED);

or

$objPHPExcel->getActiveSheet()->getStyle('A3:C5')->getFont()->getColor()->setARGB(PHPExcel_Style_Color::COLOR_RED);

or

$objPHPExcel->getActiveSheet()->getStyle('2:4')->getFont()->getColor()->setARGB(PHPExcel_Style_Color::COLOR_RED);