0

I am trying to get custom colors working in libXL, I noticed there are like 80 basic colors or so in the library, does anyone know how to set a custom color for a cell using this library since in the documentation there is not any kind of information related to it.

Right now I have tried to do the following:

 $doc = new XL_excel(true);
 $createSheet = $doc->createSheet();
          for( $i=0; $i<32000; $i++ ){
             $format = $doc->excel->addFormat();
             $format->patternForegroundColor($i);
             $format->fillPattern(ExcelFormat::FILLPATTERN_SOLID);
             $doc->excel->getSheet()->setCellFormat(8+$i, 2, $format);
         }

All the colors I get for this library are Integers from 1 to 80 after that I get no colors or repeated ones, I have tried using integers until 32000

enter image description here

DiegoCoderPlus
  • 760
  • 6
  • 14

4 Answers4

0

I don't think there are custom colors available yet, see also official libxl documentation http://libxl.com/colors.html

Johannes
  • 11
  • 2
0

Use colorPack method of book object. Be sure, that rgbMode is set to true. In C#:

book.rgbMode = true;
someFormat.patternForegroundColor = book.colorPack(217,217,217);

See http://www.libxl.com/workbook.html

0

gabortoth, Thank you, your answer really helped me. There is another feature that I discovered. When rgbmode is turned on, constants with preset colors stop working correctly. Made my own and use them. Could not only understand what to do with constants

const COLOR_DEFAULT_FOREGROUND = 64;
const COLOR_DEFAULT_BACKGROUND = 65;

The rest I quote below

const RGB_COLOR_BLACK = 0;
const RGB_COLOR_WHITE = 16777215;
const RGB_COLOR_RED = 16711680;
const RGB_COLOR_BRIGHTGREEN = 65280;
const RGB_COLOR_BLUE = 255;
const RGB_COLOR_YELLOW = 16776960;
const RGB_COLOR_PINK = 16711935;
const RGB_COLOR_TURQUOISE = 65535;
const RGB_COLOR_DARKRED = 8388608;
const RGB_COLOR_GREEN = 32768;
const RGB_COLOR_DARKBLUE = 128;
const RGB_COLOR_DARKYELLOW = 8421376;
const RGB_COLOR_VIOLET = 8388736;
const RGB_COLOR_TEAL = 32896;
const RGB_COLOR_GRAY25 = 12632256;
const RGB_COLOR_GRAY50 = 8421504;
const RGB_COLOR_PERIWINKLE_CF = 10066431;
const RGB_COLOR_PLUM_CF = 10040166;
const RGB_COLOR_IVORY_CF = 16777164;
const RGB_COLOR_LIGHTTURQUOISE_CF = 13434879;
const RGB_COLOR_DARKPURPLE_CF = 6684774;
const RGB_COLOR_CORAL_CF = 16744576;
const RGB_COLOR_OCEANBLUE_CF = 26316;
const RGB_COLOR_ICEBLUE_CF = 13421823;
const RGB_COLOR_DARKBLUE_CL = 128;
const RGB_COLOR_PINK_CL = 16711935;
const RGB_COLOR_YELLOW_CL = 16776960;
const RGB_COLOR_TURQUOISE_CL = 65535;
const RGB_COLOR_VIOLET_CL = 8388736;
const RGB_COLOR_DARKRED_CL = 8388608;
const RGB_COLOR_TEAL_CL = 32896;
const RGB_COLOR_BLUE_CL = 255;
const RGB_COLOR_SKYBLUE = 52479;
const RGB_COLOR_LIGHTTURQUOISE = 13434879;
const RGB_COLOR_LIGHTGREEN = 13434828;
const RGB_COLOR_LIGHTYELLOW = 16777113;
const RGB_COLOR_PALEBLUE = 10079487;
const RGB_COLOR_ROSE = 16751052;
const RGB_COLOR_LAVENDER = 13408767;
const RGB_COLOR_TAN = 16764057;
const RGB_COLOR_LIGHTBLUE = 3368703;
const RGB_COLOR_AQUA = 3394764;
const RGB_COLOR_LIME = 10079232;
const RGB_COLOR_GOLD = 16763904;
const RGB_COLOR_LIGHTORANGE = 16750848;
const RGB_COLOR_ORANGE = 16737792;
const RGB_COLOR_BLUEGRAY = 6710937;
const RGB_COLOR_GRAY40 = 9868950;
const RGB_COLOR_DARKTEAL = 13158;
const RGB_COLOR_SEAGREEN = 3381606;
const RGB_COLOR_DARKGREEN = 13056;
const RGB_COLOR_OLIVEGREEN = 3355392;
const RGB_COLOR_BROWN = 10040064;
const RGB_COLOR_PLUM = 10040166;
const RGB_COLOR_INDIGO = 3355545;
const RGB_COLOR_GRAY80 = 3355443;
0

NOTE: 'Formats' are permanent throughout the spreadsheet.
You can't change & re-use a Format. If you assign a Format to cell A, then change the color of the Format and apply it to cell B, then cell A now has the color of cell B.

Pierre
  • 4,114
  • 2
  • 34
  • 39