Control from array

Topics: User Forum
Sep 22, 2010 at 9:09 PM
Edited Sep 22, 2010 at 9:10 PM

Before I get into my issue I wanted to say thank you so much for your library, it's made my job so much easier!

On to my issue, thanks to this library I'm able to create stylesheets with pretty colors and sparklies and all other nice things that help my users do their work. At first I was using the ->getActiveSheet()->setCellValue("H".$count, $value); method to add data, but I was finding that was becoming quite cumbersome when adding a new column.

Recently, I found out about ->getActiveSheet()->fromArray(array($data), NULL, "A".$count); to insert data now and it's made it even easier. The only issue that I have now is I'm having trouble figuring out how (if it's even possible) to apply overall column styles and soforth in a more dynamic manner? Currently, I've been using ->getActiveSheet()->getColumnDimension("A")->setAutoSize(true); to set autosize & visible and getActiveSheet()->getStyle("D2:D".$count)->to set number formatting and soforth. When adding a new column in the array for fromArray() it's almost too easy to add a new line and forget to add/shift any new style information that's already been programmed.

So, to cut a tl;dr short, is it possible to pass a full array including value, style information, autosize setting, visibility, number formatting, etc in one fell swoop with fromArray and I'm just overlooking that functionality, or am I resigned to my current method?

Thank you very much!

EDIT: Forgot to mention I'm using 1.7.2 currently

Sep 22, 2010 at 10:07 PM

Take a look at the applyFromArray() method for setting styles:

$styleArray = array(
       'borders' => array(
              'outline' => array(
                     'style' => PHPExcel_Style_Border::BORDER_THICK,
                     'color' => array('argb' => 'FFFF0000'),

which can be used to apply a whole series of style features (font, cell colour/pattern, alignment, numbert format, etc. to a range of cells in one step. Appendix A of the developer documentation shows all the style features that can be set from an array.

Cell value, however, always has to be set separately to style.