\PhpOffice\PhpSpreadsheet\StyleNumberFormat

Summary

Methods
Properties
Constants
__construct()
bindParent()
getIsSupervisor()
getActiveSheet()
getSelectedCells()
getActiveCell()
__clone()
exportArray()
getSharedComponent()
getStyleArray()
applyFromArray()
getFormatCode()
setFormatCode()
getBuiltInFormatCode()
setBuiltInFormatCode()
builtInFormatCode()
builtInFormatCodeIndex()
getHashCode()
toFormattedString()
No public properties found
FORMAT_GENERAL
FORMAT_TEXT
FORMAT_NUMBER
FORMAT_NUMBER_00
FORMAT_NUMBER_COMMA_SEPARATED1
FORMAT_NUMBER_COMMA_SEPARATED2
FORMAT_PERCENTAGE
FORMAT_PERCENTAGE_00
FORMAT_DATE_YYYYMMDD2
FORMAT_DATE_YYYYMMDD
FORMAT_DATE_DDMMYYYY
FORMAT_DATE_DMYSLASH
FORMAT_DATE_DMYMINUS
FORMAT_DATE_DMMINUS
FORMAT_DATE_MYMINUS
FORMAT_DATE_XLSX14
FORMAT_DATE_XLSX15
FORMAT_DATE_XLSX16
FORMAT_DATE_XLSX17
FORMAT_DATE_XLSX22
FORMAT_DATE_DATETIME
FORMAT_DATE_TIME1
FORMAT_DATE_TIME2
FORMAT_DATE_TIME3
FORMAT_DATE_TIME4
FORMAT_DATE_TIME5
FORMAT_DATE_TIME6
FORMAT_DATE_TIME7
FORMAT_DATE_TIME8
FORMAT_DATE_YYYYMMDDSLASH
FORMAT_CURRENCY_USD_SIMPLE
FORMAT_CURRENCY_USD
FORMAT_CURRENCY_EUR_SIMPLE
FORMAT_CURRENCY_EUR
FORMAT_ACCOUNTING_USD
FORMAT_ACCOUNTING_EUR
exportArray1()
exportArray2()
$isSupervisor
$parent
$parentPropertyName
$builtInFormats
$flippedBuiltInFormats
$formatCode
$builtInFormatCode
N/A
fillBuiltInFormatCodes()
setLowercaseCallback()
escapeQuotesCallback()
formatAsDate()
formatAsPercentage()
formatAsFraction()
mergeComplexNumberFormatMasks()
processComplexNumberFormatMask()
complexNumberFormatMask()
formatStraightNumericValue()
formatAsNumber()
splitFormatCompare()
splitFormat()
$dateFormatReplacements
$dateFormatReplacements24
$dateFormatReplacements12
N/A

Constants

FORMAT_GENERAL

FORMAT_GENERAL = 'General'

FORMAT_TEXT

FORMAT_TEXT = '@'

FORMAT_NUMBER

FORMAT_NUMBER = '0'

FORMAT_NUMBER_00

FORMAT_NUMBER_00 = '0.00'

FORMAT_NUMBER_COMMA_SEPARATED1

FORMAT_NUMBER_COMMA_SEPARATED1 = '#,##0.00'

FORMAT_NUMBER_COMMA_SEPARATED2

FORMAT_NUMBER_COMMA_SEPARATED2 = '#,##0.00_-'

FORMAT_PERCENTAGE

FORMAT_PERCENTAGE = '0%'

FORMAT_PERCENTAGE_00

FORMAT_PERCENTAGE_00 = '0.00%'

FORMAT_DATE_YYYYMMDD2

FORMAT_DATE_YYYYMMDD2 = 'yyyy-mm-dd'

FORMAT_DATE_YYYYMMDD

FORMAT_DATE_YYYYMMDD = 'yyyy-mm-dd'

FORMAT_DATE_DDMMYYYY

FORMAT_DATE_DDMMYYYY = 'dd/mm/yyyy'

FORMAT_DATE_DMYSLASH

FORMAT_DATE_DMYSLASH = 'd/m/yy'

FORMAT_DATE_DMYMINUS

FORMAT_DATE_DMYMINUS = 'd-m-yy'

FORMAT_DATE_DMMINUS

FORMAT_DATE_DMMINUS = 'd-m'

FORMAT_DATE_MYMINUS

FORMAT_DATE_MYMINUS = 'm-yy'

FORMAT_DATE_XLSX14

FORMAT_DATE_XLSX14 = 'mm-dd-yy'

FORMAT_DATE_XLSX15

FORMAT_DATE_XLSX15 = 'd-mmm-yy'

FORMAT_DATE_XLSX16

FORMAT_DATE_XLSX16 = 'd-mmm'

FORMAT_DATE_XLSX17

FORMAT_DATE_XLSX17 = 'mmm-yy'

FORMAT_DATE_XLSX22

FORMAT_DATE_XLSX22 = 'm/d/yy h:mm'

FORMAT_DATE_DATETIME

FORMAT_DATE_DATETIME = 'd/m/yy h:mm'

FORMAT_DATE_TIME1

FORMAT_DATE_TIME1 = 'h:mm AM/PM'

FORMAT_DATE_TIME2

FORMAT_DATE_TIME2 = 'h:mm:ss AM/PM'

FORMAT_DATE_TIME3

FORMAT_DATE_TIME3 = 'h:mm'

FORMAT_DATE_TIME4

FORMAT_DATE_TIME4 = 'h:mm:ss'

FORMAT_DATE_TIME5

FORMAT_DATE_TIME5 = 'mm:ss'

FORMAT_DATE_TIME6

FORMAT_DATE_TIME6 = 'h:mm:ss'

FORMAT_DATE_TIME7

FORMAT_DATE_TIME7 = 'i:s.S'

FORMAT_DATE_TIME8

FORMAT_DATE_TIME8 = 'h:mm:ss;@'

FORMAT_DATE_YYYYMMDDSLASH

FORMAT_DATE_YYYYMMDDSLASH = 'yyyy/mm/dd;@'

FORMAT_CURRENCY_USD_SIMPLE

FORMAT_CURRENCY_USD_SIMPLE = '"$"#,##0.00_-'

FORMAT_CURRENCY_USD

FORMAT_CURRENCY_USD = '$#,##0_-'

FORMAT_CURRENCY_EUR_SIMPLE

FORMAT_CURRENCY_EUR_SIMPLE = '#,##0.00_-"€"'

FORMAT_CURRENCY_EUR

FORMAT_CURRENCY_EUR = '#,##0_-"€"'

FORMAT_ACCOUNTING_USD

FORMAT_ACCOUNTING_USD = '_("$"* #,##0.00_);_("$"* \\(#,##0.00\\);_("$"* "-"??_);_(@_)'

FORMAT_ACCOUNTING_EUR

FORMAT_ACCOUNTING_EUR = '_("€"* #,##0.00_);_("€"* \\(#,##0.00\\);_("€"* "-"??_);_(@_)'

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

$builtInFormats

$builtInFormats : array

Excel built-in number formats.

Type

array

$flippedBuiltInFormats

$flippedBuiltInFormats : array

Excel built-in number formats (flipped, for faster lookups).

Type

array

$formatCode

$formatCode : string

Format Code.

Type

string

$builtInFormatCode

$builtInFormatCode : string

Built-in format Code.

Type

string

$dateFormatReplacements

$dateFormatReplacements : array

Search/replace values to convert Excel date/time format masks to PHP format masks.

Type

array

$dateFormatReplacements24

$dateFormatReplacements24 : array

Search/replace values to convert Excel date/time format masks hours to PHP format masks (24 hr clock).

Type

array

$dateFormatReplacements12

$dateFormatReplacements12 : array

Search/replace values to convert Excel date/time format masks hours to PHP format masks (12 hr clock).

Type

array

Methods

__construct()

__construct(bool  $isSupervisor = false, bool  $isConditional = false) : mixed

Create a new NumberFormat.

Parameters

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\NumberFormat

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

Only used for style supervisor.

Returns

\PhpOffice\PhpSpreadsheet\Style\NumberFormat —

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')->getNumberFormat()->applyFromArray( [ 'formatCode' => NumberFormat::FORMAT_CURRENCY_EUR_SIMPLE ] );

Parameters

array $pStyles

Array containing style information

Returns

$this —

getFormatCode()

getFormatCode() : string

Get Format Code.

Returns

string —

setFormatCode()

setFormatCode(string  $pValue) : $this

Set Format Code.

Parameters

string $pValue

see self::FORMAT_*

Returns

$this —

getBuiltInFormatCode()

getBuiltInFormatCode() : int

Get Built-In Format Code.

Returns

int —

setBuiltInFormatCode()

setBuiltInFormatCode(int  $pValue) : $this

Set Built-In Format Code.

Parameters

int $pValue

Returns

$this —

builtInFormatCode()

builtInFormatCode(int  $pIndex) : string

Get built-in format code.

Parameters

int $pIndex

Returns

string —

builtInFormatCodeIndex()

builtInFormatCodeIndex(string  $formatCode) : bool|int

Get built-in format code index.

Parameters

string $formatCode

Returns

bool|int —

getHashCode()

getHashCode() : string

Get hash code.

Returns

string —

Hash code

toFormattedString()

toFormattedString(mixed  $value, string  $format, array  $callBack = null) : string

Convert a value in a pre-defined format to a PHP string.

Parameters

mixed $value

Value to format

string $format

Format code, see = self::FORMAT_*

array $callBack

Callback function for additional formatting of string

Returns

string —

Formatted string

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

fillBuiltInFormatCodes()

fillBuiltInFormatCodes() : void

Fill built-in format codes.

setLowercaseCallback()

setLowercaseCallback(mixed  $matches) : mixed

Parameters

mixed $matches

Returns

mixed —

escapeQuotesCallback()

escapeQuotesCallback(mixed  $matches) : mixed

Parameters

mixed $matches

Returns

mixed —

formatAsDate()

formatAsDate(mixed  $value, mixed  $format) : void

Parameters

mixed $value
mixed $format

formatAsPercentage()

formatAsPercentage(mixed  $value, mixed  $format) : void

Parameters

mixed $value
mixed $format

formatAsFraction()

formatAsFraction(mixed  $value, mixed  $format) : void

Parameters

mixed $value
mixed $format

mergeComplexNumberFormatMasks()

mergeComplexNumberFormatMasks(mixed  $numbers, mixed  $masks) : mixed

Parameters

mixed $numbers
mixed $masks

Returns

mixed —

processComplexNumberFormatMask()

processComplexNumberFormatMask(mixed  $number, mixed  $mask) : mixed

Parameters

mixed $number
mixed $mask

Returns

mixed —

complexNumberFormatMask()

complexNumberFormatMask(mixed  $number, mixed  $mask, mixed  $splitOnPoint = true) : mixed

Parameters

mixed $number
mixed $mask
mixed $splitOnPoint

Returns

mixed —

formatStraightNumericValue()

formatStraightNumericValue(mixed  $value, mixed  $format, array  $matches, mixed  $useThousands, mixed  $number_regex) : mixed

Parameters

mixed $value
mixed $format
array $matches
mixed $useThousands
mixed $number_regex

Returns

mixed —

formatAsNumber()

formatAsNumber(mixed  $value, mixed  $format) : mixed

Parameters

mixed $value
mixed $format

Returns

mixed —

splitFormatCompare()

splitFormatCompare(mixed  $value, mixed  $cond, mixed  $val, mixed  $dfcond, mixed  $dfval) : mixed

Parameters

mixed $value
mixed $cond
mixed $val
mixed $dfcond
mixed $dfval

Returns

mixed —

splitFormat()

splitFormat(mixed  $sections, mixed  $value) : mixed

Parameters

mixed $sections
mixed $value

Returns

mixed —