Styling discontinuous ranges of cells

Topics: Developer Forum, User Forum
Jan 17, 2013 at 12:17 PM

Hi all,

I use PHPExcel 1.7.8. I have hundreds of cell to style in my worksheet. I realized I could not use the standard range styling receipes to manage to get them styled at once. I used both methods :

  • $myworksheet->duplicateStyleArray($mystyle,$myrange);
  • $myworksheet->getStyle($range)->applyFromArray($mystyle);

Say we have $range defined like this : $range = "A1,B12,C80,AL120";

I read the code of Worksheet, style and applyFromRange but PHPExcel_Cell::coordinateFromString($range) does not handle discontinuous ranges.

I managed to get my cell styled one by one in a loop, but as I have thousands cells to style, I get a php timeout. Nevertheless I get what I wanted but I'm a little annoyed by the amount of time the "one by one" operation takes and I wonder if there's another way to perform this to speed it up.

Any help will be appreciated.


Jan 17, 2013 at 1:50 PM

Just some stats for this :

I'm styling cells one by one with red,orange, yellow and red backgrounds.

  • reds 3588
  • greens 7
  • oranges 55
  • yellows 62

total 3712 cells
time styling: 24 seconds