PHP Spreadsheet color codes

PHP Spreadsheet color codes

Can somebody explain this to me? I have tried several HEX codes for PHP Spreadsheet but none give the expected color.

https://phpspreadsheet.readthedocs.io/en/develop/topics/recipes/

$styleArray = array(
    'font' => array(
        'bold' => true,
    ),
    'alignment' => array(
        'horizontal' => \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_RIGHT,
    ),
    'borders' => array(
        'top' => array(
            'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,
        ),
    ),
    'fill' => array(
        'fillType' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_GRADIENT_LINEAR,
        'rotation' => 90,
        'startColor' => array(
            'argb' => 'FFA0A0A0',
        ),
        'endColor' => array(
            'argb' => 'FFFFFFFF',
        ),
    ),
);

Open in new window


The FFA0A0A0 is a dark grey but I want to use a light gray. Every color code I try is way off.

It has 8 instead of 6. I think the first 2 is the pallet and that is where I am getting lost.
LVL 7
Robert SaylorSenior DeveloperAsked:
Who is Participating?
 
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
I am being told that any rgb color should work for Excel

Can you try running the colors you see here http://jsbin.com/cebayafoha/edit?html,output in your web browser and note if they look like the screenshot I have added.  (There is one extra box in the live code).  Then run those exact colors in your php program and lets see if those match.  

It could be screen calibration or the way the php library is rendering?  I don't have time today, but I would be willing to try the php library on my end to see if I get the same. I don't have time today. Possibly tomorrow otherwise it would have to be next week.  You can also play with using black and set the alpha channel to different percentages to get the gray you are after.
0
 
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
I wonder if part of your problem is your hex codes. Hex should have 6 characters. You have 8.  http://htmlcolorcodes.com/
0
 
Robert SaylorSenior DeveloperAuthor Commented:
tried with both 6 and 8. The example is using 8 from there site.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
Compare your codes to a color chart and then make your own.

When I tried your color FFA0A0A0 and then dropped off the last two characters FFA0A0, you can see they appear to be more on the pink side than gray.  The first two box's represent your selected colors.  I have a link to an html output, the code and screen shot.

http://jsbin.com/cebayafoha/edit?html,output
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>color test</title>
  <style>
    body{background-color:#000}
    .box{width:100px;height:100px;}
    .a{background-color:#FFA0A0A0;}
    .b{background-color:#FFA0A0;}
    .c{background-color:#F5F5F5;}
    .d{background-color:#D3D3D3;}
    .e{background-color:#808080;}
  </style>
</head>
<body>
  <div class="box a"></div>
  <div class="box b"></div>
  <div class="box c"></div>
  <div class="box d"></div>
  <div class="box e"></div>  
  
</body>
</html>

Open in new window


Capture.JPG
Gray can be a tricky color and especially if your monitor is not adjusted properly because what you at first perceive as gray on it's own can take on pink, green or blue tones depending on a background or monitor calibration.

Use the the color charts like https://www.computerhope.com/htmcolor.htm to test. Also note that if you click on some colors will have a generic name and others will have a w3c name where you can use the w3c name in place of the hex number (without the hashtag) and should see the same.  The complete list can be found https://www.w3.org/TR/2017/CR-css-color-3-20171205/#html4
In short, your answer is to check the expected color on these color charts wtih what you are using and only use 6 characters.
0
 
Robert SaylorSenior DeveloperAuthor Commented:
I think you are treating it like HTML where it's Excel. I am using ARGB.

Just found this link going to research this some more.

https://stackoverflow.com/questions/23136223/php-convert-argb-to-rgba/23136532#23136532
0
 
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
OK, you are correct. In that case, your color does seem correct.  The FF should be 100% and the remaining characters are RGB which would be the same as the last div.

https://github.com/PHPOffice/PhpSpreadsheet/blob/ac1c7a2c7dc2aceeeca4a9c2f2329ecd77396c2b/src/PhpSpreadsheet/Style/Color.php

When I have time I will download and try this out too if you have not found an answer.
0
 
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
What happens if you try ffe5e5e5 or ffcccccc?
0
 
Robert SaylorSenior DeveloperAuthor Commented:
2018-01-31_13-46-49.jpgThe "ffe5e5e5" was white but the "ffcccccc" was gray.
0
 
Robert SaylorSenior DeveloperAuthor Commented:
Also, I tried "ffb3c6d3" prior and gave the same gray as "ffcccccc". Looking more into excel that is the 25% gray option so this might be as light as it goes.2018-01-31_13-52-08.jpg
0
 
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
A long time ago I have generated excel files via vbscript and asp and seem to remember using html colors although I don't think I paid too much attention and was mostly using black background with white text. You may be on to something with color palate being limited.

Let's add vba topic to the question and see if somebody that specifically programs to generate excel files on the Microsoft side has some answers.
0
 
Robert SaylorSenior DeveloperAuthor Commented:
Thanks and sounds good. Thanks for troubleshooting with me.
0
 
Robert SaylorSenior DeveloperAuthor Commented:
Ultimately Scott's answer would be correct. I am using an older version of Excel and I think that is why the pallet did not change when I tried different RGB combinations.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.