Constants

NAMED_COLORS

NAMED_COLORS = ['Black', 'White', 'Red', 'Green', 'Blue', 'Yellow', 'Magenta', 'Cyan']

COLOR_BLACK

COLOR_BLACK = 'FF000000'

COLOR_WHITE

COLOR_WHITE = 'FFFFFFFF'

COLOR_RED

COLOR_RED = 'FFFF0000'

COLOR_DARKRED

COLOR_DARKRED = 'FF800000'

COLOR_BLUE

COLOR_BLUE = 'FF0000FF'

COLOR_DARKBLUE

COLOR_DARKBLUE = 'FF000080'

COLOR_GREEN

COLOR_GREEN = 'FF00FF00'

COLOR_DARKGREEN

COLOR_DARKGREEN = 'FF008000'

COLOR_YELLOW

COLOR_YELLOW = 'FFFFFF00'

COLOR_DARKYELLOW

COLOR_DARKYELLOW = 'FF808000'

Properties

$isSupervisor

$isSupervisor : bool

Supervisor?

Type

bool

$parent

$parent : \PhpOffice\PhpSpreadsheet\Spreadsheet|\PhpOffice\PhpSpreadsheet\Style\Style

Parent. Only used for supervisor.

Type

Style

$parentPropertyName

$parentPropertyName : null|string

Parent property name.

Type

null|string

$indexedColors

$indexedColors : array

Indexed colors array.

Type

array

$argb

$argb : string

ARGB - Alpha RGB.

Type

string

Methods

__construct()

__construct(string  $pARGB = self::COLOR_BLACK, bool  $isSupervisor = false, bool  $isConditional = false) : mixed

Create a new Color.

Parameters

string $pARGB

ARGB value for the colour

bool $isSupervisor

Flag indicating if this is a supervisor or not Leave this value at default unless you understand exactly what its ramifications are

bool $isConditional

Flag indicating if this is a conditional style or not Leave this value at default unless you understand exactly what its ramifications are

Returns

mixed —

bindParent()

bindParent(\PhpOffice\PhpSpreadsheet\Spreadsheet|\PhpOffice\PhpSpreadsheet\Style\Style  $parent, null|string  $parentPropertyName = null) : $this

Bind parent. Only used for supervisor.

Parameters

\PhpOffice\PhpSpreadsheet\Spreadsheet|\PhpOffice\PhpSpreadsheet\Style\Style $parent
null|string $parentPropertyName

Returns

$this —

getIsSupervisor()

getIsSupervisor() : bool

Is this a supervisor or a cell style component?

Returns

bool —

getActiveSheet()

getActiveSheet() : \PhpOffice\PhpSpreadsheet\Worksheet\Worksheet

Get the currently active sheet. Only used for supervisor.

Returns

\PhpOffice\PhpSpreadsheet\Worksheet\Worksheet —

getSelectedCells()

getSelectedCells() : string

Get the currently active cell coordinate in currently active sheet.

Only used for supervisor.

Returns

string —

E.g. 'A1'

getActiveCell()

getActiveCell() : string

Get the currently active cell coordinate in currently active sheet.

Only used for supervisor.

Returns

string —

E.g. 'A1'

__clone()

__clone() : mixed

Implement PHP __clone to create a deep clone, not just a shallow copy.

Returns

mixed —

exportArray()

exportArray() : array

Export style as array.

Available to anything which extends this class: Alignment, Border, Borders, Color, Fill, Font, NumberFormat, Protection, and Style.

Returns

array —

getSharedComponent()

getSharedComponent() : \PhpOffice\PhpSpreadsheet\Style\Color

Get the shared style component for the currently active cell in currently active sheet.

Only used for style supervisor.

Returns

\PhpOffice\PhpSpreadsheet\Style\Color —

getStyleArray()

getStyleArray(array  $array) : array

Build style array from subcomponents.

Parameters

array $array

Returns

array —

applyFromArray()

applyFromArray(array  $pStyles) : $this

Apply styles from array.

$spreadsheet->getActiveSheet()->getStyle('B2')->getFont()->getColor()->applyFromArray(['rgb' => '808080']);

Parameters

array $pStyles

Array containing style information

Returns

$this —

getARGB()

getARGB() : string

Get ARGB.

Returns

string —

setARGB()

setARGB(string  $pValue) : $this

Set ARGB.

Parameters

string $pValue

see self::COLOR_*

Returns

$this —

getRGB()

getRGB() : string

Get RGB.

Returns

string —

setRGB()

setRGB(string  $pValue) : $this

Set RGB.

Parameters

string $pValue

RGB value

Returns

$this —

getRed()

getRed(string  $RGB, bool  $hex = true) : string

Get the red colour component of an RGB value.

Parameters

string $RGB

The colour as an RGB value (e.g. FF00CCCC or CCDDEE

bool $hex

Flag indicating whether the component should be returned as a hex or a decimal value

Returns

string —

The red colour component

getGreen()

getGreen(string  $RGB, bool  $hex = true) : string

Get the green colour component of an RGB value.

Parameters

string $RGB

The colour as an RGB value (e.g. FF00CCCC or CCDDEE

bool $hex

Flag indicating whether the component should be returned as a hex or a decimal value

Returns

string —

The green colour component

getBlue()

getBlue(string  $RGB, bool  $hex = true) : string

Get the blue colour component of an RGB value.

Parameters

string $RGB

The colour as an RGB value (e.g. FF00CCCC or CCDDEE

bool $hex

Flag indicating whether the component should be returned as a hex or a decimal value

Returns

string —

The blue colour component

changeBrightness()

changeBrightness(string  $hex, float  $adjustPercentage) : string

Adjust the brightness of a color.

Parameters

string $hex

The colour as an RGBA or RGB value (e.g. FF00CCCC or CCDDEE)

float $adjustPercentage

The percentage by which to adjust the colour as a float from -1 to 1

Returns

string —

The adjusted colour as an RGBA or RGB value (e.g. FF00CCCC or CCDDEE)

indexedColor()

indexedColor(int  $pIndex, bool  $background = false) : self

Get indexed color.

Parameters

int $pIndex

Index entry point into the colour array

bool $background

Flag to indicate whether default background or foreground colour should be returned if the indexed colour doesn't exist

Returns

self —

getHashCode()

getHashCode() : string

Get hash code.

Returns

string —

Hash code

exportArray1()

exportArray1() : array

Abstract method to be implemented in anything which extends this class.

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.

Returns

array —

exportArray2()

exportArray2(array  $exportedArray, string  $index, mixed  $objOrValue) : void

Populate array from exportArray1.

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

array $exportedArray
string $index
mixed $objOrValue

getColourComponent()

getColourComponent(string  $RGB, int  $offset, bool  $hex = true) : string

Get a specified colour component of an RGB value.

Parameters

string $RGB

The colour as an RGB value (e.g. FF00CCCC or CCDDEE

int $offset

Position within the RGB value to extract

bool $hex

Flag indicating whether the component should be returned as a hex or a decimal value

Returns

string —

The extracted colour component