Link to home
Start Free TrialLog in
Avatar of diarmuidflaherty
diarmuidflaherty

asked on

PEAR Spreadsheet_Excel_Writer addformat

Hi,
Is it possible to add to a default format for a single cell and retain the original format for the remaining cells.
e.g. I have a default format lets say size 10, align right
I'm printing out a table of numbers which i want all to use the default format above.

But my question is can i add another pice of formating to the default for specific cells
e.g. numbers over 10 are blue
                      over 20 are red
                      over 30 are green

my table is printing out fine with the correct default format, but if i go to add another format(with the same name) it just overwrites the previous formatting.

i've also tried setFgColor to the original format but this changes the default format and is applied to all the cells.
I've also tried 2 write statements, but again this overwrites the existing format.

So basically is it possible to apply 2 formats to a cell, 1 default and 1 depending on cell value????

Please Help
Diarmuid
Avatar of siranm
siranm

I would do a wrapper to the function... the wrapper would be concient on the content you want to write to a cell, and apply formats consistently.
what i mean is:
I would do a wrapper to the function... the wrapper would know the content you want to write to a cell, and apply formats consistently.
Avatar of diarmuidflaherty

ASKER

OK maybe i didn't explain it fully.... or possibly a bad example.

I'm passing in an array of data with data,format, color
data = cell data
format = number,text,date,time etc
color = cell color

i have a switch statement seperating the array on format-> i have all the default formats
but i want to add the color that is passed to the default format, without overiding it.
so it's not quite as cut and dry as the previous example....

e.g.
testdata, number, black
testdata, number, green

both should have the number format, but different colors

Hope this makes it clearer
Diarmuid
i think it doesnt...


can you post some code so i can see what can be modified ?
foreach $data......
{
      switch($data['format'])
      case number:
            NEED A LINE HERE
            $sheet1->write(0,0,$data['data'],$num_format)
            break;
      case text:
            NEED A LINE HERE
            $sheet1->write(0,0,$data['data'],$text_format)
            break;
      case........
}
I'm at work so don't hav the exact code... but thats basically it...
I need a line above to add the the color stored in $data[color]
so if the color is different next time through the loop it doesn't change the original format

setFgColor changes the default and the last color in the loop is applied to all cells of that format
addformat overwrites the original format, so i lose my allignment and size etc...but it does give the correct colors....

I think i'm pretty close... probably just something small i am missing
if you do something similar to what i'm posting, your problem is solved ... is it ?

switch($data["color"]){
case 'green':
    $color = green_color_string
case 'black':
    $color = black_color_string
}
 
$num_format = whatever_you_do_+_$color
$text_format = whatever_you_do_+_$color
 
foreach $data......
{
      switch($data['format'])
      case number:
            NEED A LINE HERE
            $sheet1->write(0,0,$data['data'],$num_format)
            break;
      case text:
            NEED A LINE HERE
            $sheet1->write(0,0,$data['data'],$text_format)
            break;
      case........
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of diarmuidflaherty
diarmuidflaherty

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ok....