Color
extends Supervisor
in package
Table of Contents
Constants
- COLOR_BLACK = 'FF000000'
- COLOR_BLUE = 'FF0000FF'
- COLOR_CYAN = 'FF00FFFF'
- COLOR_DARKBLUE = 'FF000080'
- COLOR_DARKGREEN = 'FF008000'
- COLOR_DARKRED = 'FF800000'
- COLOR_DARKYELLOW = 'FF808000'
- COLOR_GREEN = 'FF00FF00'
- COLOR_MAGENTA = 'FFFF00FF'
- COLOR_RED = 'FFFF0000'
- COLOR_WHITE = 'FFFFFFFF'
- COLOR_YELLOW = 'FFFFFF00'
- NAMED_COLOR_TRANSLATIONS = ['Black' => self::COLOR_BLACK, 'White' => self::COLOR_WHITE, 'Red' => self::COLOR_RED, 'Green' => self::COLOR_GREEN, 'Blue' => self::COLOR_BLUE, 'Yellow' => self::COLOR_YELLOW, 'Magenta' => self::COLOR_MAGENTA, 'Cyan' => self::COLOR_CYAN]
- NAMED_COLORS = ['Black', 'White', 'Red', 'Green', 'Blue', 'Yellow', 'Magenta', 'Cyan']
- VALIDATE_ARGB_SIZE = 8
- VALIDATE_COLOR_6 = '/^[A-F0-9]{6}$/i'
- VALIDATE_COLOR_8 = '/^[A-F0-9]{8}$/i'
- VALIDATE_RGB_SIZE = 6
- INDEXED_COLORS = [ 1 => 'FF000000', // System Colour #1 - Black 2 => 'FFFFFFFF', // System Colour #2 - White 3 => 'FFFF0000', // System Colour #3 - Red 4 => 'FF00FF00', // System Colour #4 - Green 5 => 'FF0000FF', // System Colour #5 - Blue 6 => 'FFFFFF00', // System Colour #6 - Yellow 7 => 'FFFF00FF', // System Colour #7- Magenta 8 => 'FF00FFFF', // System Colour #8- Cyan 9 => 'FF800000', // Standard Colour #9 10 => 'FF008000', // Standard Colour #10 11 => 'FF000080', // Standard Colour #11 12 => 'FF808000', // Standard Colour #12 13 => 'FF800080', // Standard Colour #13 14 => 'FF008080', // Standard Colour #14 15 => 'FFC0C0C0', // Standard Colour #15 16 => 'FF808080', // Standard Colour #16 17 => 'FF9999FF', // Chart Fill Colour #17 18 => 'FF993366', // Chart Fill Colour #18 19 => 'FFFFFFCC', // Chart Fill Colour #19 20 => 'FFCCFFFF', // Chart Fill Colour #20 21 => 'FF660066', // Chart Fill Colour #21 22 => 'FFFF8080', // Chart Fill Colour #22 23 => 'FF0066CC', // Chart Fill Colour #23 24 => 'FFCCCCFF', // Chart Fill Colour #24 25 => 'FF000080', // Chart Line Colour #25 26 => 'FFFF00FF', // Chart Line Colour #26 27 => 'FFFFFF00', // Chart Line Colour #27 28 => 'FF00FFFF', // Chart Line Colour #28 29 => 'FF800080', // Chart Line Colour #29 30 => 'FF800000', // Chart Line Colour #30 31 => 'FF008080', // Chart Line Colour #31 32 => 'FF0000FF', // Chart Line Colour #32 33 => 'FF00CCFF', // Standard Colour #33 34 => 'FFCCFFFF', // Standard Colour #34 35 => 'FFCCFFCC', // Standard Colour #35 36 => 'FFFFFF99', // Standard Colour #36 37 => 'FF99CCFF', // Standard Colour #37 38 => 'FFFF99CC', // Standard Colour #38 39 => 'FFCC99FF', // Standard Colour #39 40 => 'FFFFCC99', // Standard Colour #40 41 => 'FF3366FF', // Standard Colour #41 42 => 'FF33CCCC', // Standard Colour #42 43 => 'FF99CC00', // Standard Colour #43 44 => 'FFFFCC00', // Standard Colour #44 45 => 'FFFF9900', // Standard Colour #45 46 => 'FFFF6600', // Standard Colour #46 47 => 'FF666699', // Standard Colour #47 48 => 'FF969696', // Standard Colour #48 49 => 'FF003366', // Standard Colour #49 50 => 'FF339966', // Standard Colour #50 51 => 'FF003300', // Standard Colour #51 52 => 'FF333300', // Standard Colour #52 53 => 'FF993300', // Standard Colour #53 54 => 'FF993366', // Standard Colour #54 55 => 'FF333399', // Standard Colour #55 56 => 'FF333333', ]
Properties
- $argb : string|null
- ARGB - Alpha RGB.
- $isSupervisor : bool
- Supervisor?
- $parent : Spreadsheet|Supervisor
- Parent. Only used for supervisor.
- $parentPropertyName : string|null
- Parent property name.
- $hasChanged : bool
Methods
- __clone() : mixed
- Implement PHP __clone to create a deep clone, not just a shallow copy.
- __construct() : mixed
- Create a new Color.
- applyFromArray() : $this
- Apply styles from array.
- bindParent() : $this
- Bind parent. Only used for supervisor.
- changeBrightness() : string
- Adjust the brightness of a color.
- exportArray() : array<string|int, mixed>
- Export style as array.
- getActiveCell() : string
- Get the currently active cell coordinate in currently active sheet.
- getActiveSheet() : Worksheet
- Get the currently active sheet. Only used for supervisor.
- getARGB() : string|null
- Get ARGB.
- getBlue() : int|string
- Get the blue colour component of an RGB value.
- getGreen() : int|string
- Get the green colour component of an RGB value.
- getHasChanged() : bool
- getHashCode() : string
- Get hash code.
- getIsSupervisor() : bool
- Is this a supervisor or a cell style component?
- getRed() : int|string
- Get the red colour component of an RGB value.
- getRGB() : string
- Get RGB.
- getSelectedCells() : string
- Get the currently active cell coordinate in currently active sheet.
- getSharedComponent() : self
- Get the shared style component for the currently active cell in currently active sheet.
- getStyleArray() : array<string|int, mixed>
- Build style array from subcomponents.
- indexedColor() : self
- Get indexed color.
- setARGB() : $this
- Set ARGB.
- setRGB() : $this
- Set RGB.
- exportArray1() : array<string|int, mixed>
- Abstract method to be implemented in anything which extends this class.
- exportArray2() : void
- Populate array from exportArray1.
- getColourComponent() : int|string
- Get a specified colour component of an RGB value.
- validateColor() : string
Constants
COLOR_BLACK
public
mixed
COLOR_BLACK
= 'FF000000'
COLOR_BLUE
public
mixed
COLOR_BLUE
= 'FF0000FF'
COLOR_CYAN
public
mixed
COLOR_CYAN
= 'FF00FFFF'
COLOR_DARKBLUE
public
mixed
COLOR_DARKBLUE
= 'FF000080'
COLOR_DARKGREEN
public
mixed
COLOR_DARKGREEN
= 'FF008000'
COLOR_DARKRED
public
mixed
COLOR_DARKRED
= 'FF800000'
COLOR_DARKYELLOW
public
mixed
COLOR_DARKYELLOW
= 'FF808000'
COLOR_GREEN
public
mixed
COLOR_GREEN
= 'FF00FF00'
COLOR_MAGENTA
public
mixed
COLOR_MAGENTA
= 'FFFF00FF'
COLOR_RED
public
mixed
COLOR_RED
= 'FFFF0000'
COLOR_WHITE
public
mixed
COLOR_WHITE
= 'FFFFFFFF'
COLOR_YELLOW
public
mixed
COLOR_YELLOW
= 'FFFFFF00'
NAMED_COLOR_TRANSLATIONS
public
mixed
NAMED_COLOR_TRANSLATIONS
= ['Black' => self::COLOR_BLACK, 'White' => self::COLOR_WHITE, 'Red' => self::COLOR_RED, 'Green' => self::COLOR_GREEN, 'Blue' => self::COLOR_BLUE, 'Yellow' => self::COLOR_YELLOW, 'Magenta' => self::COLOR_MAGENTA, 'Cyan' => self::COLOR_CYAN]
NAMED_COLORS
public
mixed
NAMED_COLORS
= ['Black', 'White', 'Red', 'Green', 'Blue', 'Yellow', 'Magenta', 'Cyan']
VALIDATE_ARGB_SIZE
public
mixed
VALIDATE_ARGB_SIZE
= 8
VALIDATE_COLOR_6
public
mixed
VALIDATE_COLOR_6
= '/^[A-F0-9]{6}$/i'
VALIDATE_COLOR_8
public
mixed
VALIDATE_COLOR_8
= '/^[A-F0-9]{8}$/i'
VALIDATE_RGB_SIZE
public
mixed
VALIDATE_RGB_SIZE
= 6
INDEXED_COLORS
private
mixed
INDEXED_COLORS
= [
1 => 'FF000000',
// System Colour #1 - Black
2 => 'FFFFFFFF',
// System Colour #2 - White
3 => 'FFFF0000',
// System Colour #3 - Red
4 => 'FF00FF00',
// System Colour #4 - Green
5 => 'FF0000FF',
// System Colour #5 - Blue
6 => 'FFFFFF00',
// System Colour #6 - Yellow
7 => 'FFFF00FF',
// System Colour #7- Magenta
8 => 'FF00FFFF',
// System Colour #8- Cyan
9 => 'FF800000',
// Standard Colour #9
10 => 'FF008000',
// Standard Colour #10
11 => 'FF000080',
// Standard Colour #11
12 => 'FF808000',
// Standard Colour #12
13 => 'FF800080',
// Standard Colour #13
14 => 'FF008080',
// Standard Colour #14
15 => 'FFC0C0C0',
// Standard Colour #15
16 => 'FF808080',
// Standard Colour #16
17 => 'FF9999FF',
// Chart Fill Colour #17
18 => 'FF993366',
// Chart Fill Colour #18
19 => 'FFFFFFCC',
// Chart Fill Colour #19
20 => 'FFCCFFFF',
// Chart Fill Colour #20
21 => 'FF660066',
// Chart Fill Colour #21
22 => 'FFFF8080',
// Chart Fill Colour #22
23 => 'FF0066CC',
// Chart Fill Colour #23
24 => 'FFCCCCFF',
// Chart Fill Colour #24
25 => 'FF000080',
// Chart Line Colour #25
26 => 'FFFF00FF',
// Chart Line Colour #26
27 => 'FFFFFF00',
// Chart Line Colour #27
28 => 'FF00FFFF',
// Chart Line Colour #28
29 => 'FF800080',
// Chart Line Colour #29
30 => 'FF800000',
// Chart Line Colour #30
31 => 'FF008080',
// Chart Line Colour #31
32 => 'FF0000FF',
// Chart Line Colour #32
33 => 'FF00CCFF',
// Standard Colour #33
34 => 'FFCCFFFF',
// Standard Colour #34
35 => 'FFCCFFCC',
// Standard Colour #35
36 => 'FFFFFF99',
// Standard Colour #36
37 => 'FF99CCFF',
// Standard Colour #37
38 => 'FFFF99CC',
// Standard Colour #38
39 => 'FFCC99FF',
// Standard Colour #39
40 => 'FFFFCC99',
// Standard Colour #40
41 => 'FF3366FF',
// Standard Colour #41
42 => 'FF33CCCC',
// Standard Colour #42
43 => 'FF99CC00',
// Standard Colour #43
44 => 'FFFFCC00',
// Standard Colour #44
45 => 'FFFF9900',
// Standard Colour #45
46 => 'FFFF6600',
// Standard Colour #46
47 => 'FF666699',
// Standard Colour #47
48 => 'FF969696',
// Standard Colour #48
49 => 'FF003366',
// Standard Colour #49
50 => 'FF339966',
// Standard Colour #50
51 => 'FF003300',
// Standard Colour #51
52 => 'FF333300',
// Standard Colour #52
53 => 'FF993300',
// Standard Colour #53
54 => 'FF993366',
// Standard Colour #54
55 => 'FF333399',
// Standard Colour #55
56 => 'FF333333',
]
Properties
$argb
ARGB - Alpha RGB.
protected
string|null
$argb
= null
$isSupervisor
Supervisor?
protected
bool
$isSupervisor
$parent
Parent. Only used for supervisor.
protected
Spreadsheet|Supervisor
$parent
$parentPropertyName
Parent property name.
protected
string|null
$parentPropertyName
= null
$hasChanged
private
bool
$hasChanged
= false
Methods
__clone()
Implement PHP __clone to create a deep clone, not just a shallow copy.
public
__clone() : mixed
__construct()
Create a new Color.
public
__construct([string $colorValue = self::COLOR_BLACK ][, bool $isSupervisor = false ][, bool $isConditional = false ]) : mixed
Parameters
- $colorValue : string = self::COLOR_BLACK
-
ARGB value for the colour, or named colour
- $isSupervisor : bool = false
-
Flag indicating if this is a supervisor or not Leave this value at default unless you understand exactly what its ramifications are
- $isConditional : bool = false
-
Flag indicating if this is a conditional style or not Leave this value at default unless you understand exactly what its ramifications are
applyFromArray()
Apply styles from array.
public
applyFromArray(array<string|int, mixed> $styleArray) : $this
$spreadsheet->getActiveSheet()->getStyle('B2')->getFont()->getColor()->applyFromArray(['rgb' => '808080']);
Parameters
- $styleArray : array<string|int, mixed>
-
Array containing style information
Return values
$thisbindParent()
Bind parent. Only used for supervisor.
public
bindParent(Spreadsheet|self $parent[, string|null $parentPropertyName = null ]) : $this
Parameters
- $parent : Spreadsheet|self
- $parentPropertyName : string|null = null
Return values
$thischangeBrightness()
Adjust the brightness of a color.
public
static changeBrightness(string $hexColourValue, float $adjustPercentage) : string
Parameters
- $hexColourValue : string
-
The colour as an RGBA or RGB value (e.g. FF00CCCC or CCDDEE)
- $adjustPercentage : float
-
The percentage by which to adjust the colour as a float from -1 to 1
Return values
string —The adjusted colour as an RGBA or RGB value (e.g. FF00CCCC or CCDDEE)
exportArray()
Export style as array.
public
final exportArray() : array<string|int, mixed>
Available to anything which extends this class: Alignment, Border, Borders, Color, Fill, Font, NumberFormat, Protection, and Style.
Return values
array<string|int, mixed>getActiveCell()
Get the currently active cell coordinate in currently active sheet.
public
getActiveCell() : string
Only used for supervisor.
Return values
string —E.g. 'A1'
getActiveSheet()
Get the currently active sheet. Only used for supervisor.
public
getActiveSheet() : Worksheet
Return values
WorksheetgetARGB()
Get ARGB.
public
getARGB() : string|null
Return values
string|nullgetBlue()
Get the blue colour component of an RGB value.
public
static getBlue(string $rgbValue[, bool $hex = true ]) : int|string
Parameters
- $rgbValue : string
-
The colour as an RGB value (e.g. FF00CCCC or CCDDEE
- $hex : bool = true
-
Flag indicating whether the component should be returned as a hex or a decimal value
Return values
int|string —The blue colour component
getGreen()
Get the green colour component of an RGB value.
public
static getGreen(string $rgbValue[, bool $hex = true ]) : int|string
Parameters
- $rgbValue : string
-
The colour as an RGB value (e.g. FF00CCCC or CCDDEE
- $hex : bool = true
-
Flag indicating whether the component should be returned as a hex or a decimal value
Return values
int|string —The green colour component
getHasChanged()
public
getHasChanged() : bool
Return values
boolgetHashCode()
Get hash code.
public
getHashCode() : string
Return values
string —Hash code
getIsSupervisor()
Is this a supervisor or a cell style component?
public
getIsSupervisor() : bool
Return values
boolgetRed()
Get the red colour component of an RGB value.
public
static getRed(string $rgbValue[, bool $hex = true ]) : int|string
Parameters
- $rgbValue : string
-
The colour as an RGB value (e.g. FF00CCCC or CCDDEE
- $hex : bool = true
-
Flag indicating whether the component should be returned as a hex or a decimal value
Return values
int|string —The red colour component
getRGB()
Get RGB.
public
getRGB() : string
Return values
stringgetSelectedCells()
Get the currently active cell coordinate in currently active sheet.
public
getSelectedCells() : string
Only used for supervisor.
Return values
string —E.g. 'A1'
getSharedComponent()
Get the shared style component for the currently active cell in currently active sheet.
public
getSharedComponent() : self
Only used for style supervisor.
Return values
selfgetStyleArray()
Build style array from subcomponents.
public
getStyleArray(array<string|int, mixed> $array) : array<string|int, mixed>
Parameters
- $array : array<string|int, mixed>
Return values
array<string|int, mixed>indexedColor()
Get indexed color.
public
static indexedColor(int $colorIndex[, bool $background = false ][, array<string|int, mixed>|null $palette = null ]) : self
Parameters
- $colorIndex : int
-
Index entry point into the colour array
- $background : bool = false
-
Flag to indicate whether default background or foreground colour should be returned if the indexed colour doesn't exist
- $palette : array<string|int, mixed>|null = null
Return values
selfsetARGB()
Set ARGB.
public
setARGB([string|null $colorValue = self::COLOR_BLACK ][, bool $nullStringOkay = false ]) : $this
Parameters
- $colorValue : string|null = self::COLOR_BLACK
-
ARGB value, or a named color
- $nullStringOkay : bool = false
Return values
$thissetRGB()
Set RGB.
public
setRGB([string|null $colorValue = self::COLOR_BLACK ]) : $this
Parameters
- $colorValue : string|null = self::COLOR_BLACK
-
RGB value, or a named color
Return values
$thisexportArray1()
Abstract method to be implemented in anything which extends this class.
protected
exportArray1() : array<string|int, mixed>
This method invokes exportArray2 with the names and values of all properties to be included in output array, returning that array to exportArray, then to caller.
Return values
array<string|int, mixed>exportArray2()
Populate array from exportArray1.
protected
final exportArray2(array<string|int, mixed> &$exportedArray, string $index, mixed $objOrValue) : void
This method is available to anything which extends this class. The parameter index is the key to be added to the array. The parameter objOrValue is either a primitive type, which is the value added to the array, or a Style object to be recursively added via exportArray.
Parameters
- $exportedArray : array<string|int, mixed>
- $index : string
- $objOrValue : mixed
getColourComponent()
Get a specified colour component of an RGB value.
private
static getColourComponent(string $rgbValue, int $offset[, bool $hex = true ]) : int|string
Parameters
- $rgbValue : string
-
The colour as an RGB value (e.g. FF00CCCC or CCDDEE
- $offset : int
-
Position within the RGB value to extract
- $hex : bool = true
-
Flag indicating whether the component should be returned as a hex or a decimal value
Return values
int|string —The extracted colour component
validateColor()
private
validateColor(string|null $colorValue) : string
Parameters
- $colorValue : string|null