How can i set existing style (->getStyle($pCellCoordinate)) to any cell in any worksheet

Topics: Developer Forum
Jul 31, 2012 at 7:14 AM

There is a excellent method PHPExcel_Worksheet->getStyle($pCellCoordinate). But i'm do not find any method like "setStyle"

Jul 31, 2012 at 7:34 AM
Edited Jul 31, 2012 at 7:37 AM

getStyle returns a style object. That style object has getter methods for all the style features such as font, borders, fill, protection, number masking, and those style features have setter methods:



Alternatively, you can build an array detailing all the style elements you want to set, and use the style object's applyFromArray() method

$styleThinBlackBorderOutline = array(
 'borders' => array(
  'outline' => array(
   'style' => PHPExcel_Style_Border::BORDER_THIN,
   'color' => array('argb' => 'FF000000'),

There are also methods in the Worksheet object such as setSharedStyle(), duplicateStyle() and duplicateStyleArray() that allow you to set styles to a range of cells rather than just to individual cells, or to duplicate the style set against a cell to a whole range of cells.


All this is fully detailed in the documentation and in the examples