Moodle PHP Documentation 5.1
Moodle 5.1dev (Build: 20250711) (9addea9f0ac)
PhpOffice\PhpSpreadsheet\Style\NumberFormat Class Reference
Inheritance diagram for PhpOffice\PhpSpreadsheet\Style\NumberFormat:
PhpOffice\PhpSpreadsheet\Style\Supervisor PhpOffice\PhpSpreadsheet\IComparable

Public Member Functions

 __construct (bool $isSupervisor=false, bool $isConditional=false)
 Create a new NumberFormat.
 
 __clone ()
 Implement PHP __clone to create a deep clone, not just a shallow copy.
 
 applyFromArray (array $styleArray)
 Apply styles from array.
 
 bindParent (Spreadsheet|self $parent, ?string $parentPropertyName=null)
 Bind parent.
 
 exportArray ()
 Export style as array.
 
 getActiveCell ()
 Get the currently active cell coordinate in currently active sheet.
 
 getActiveSheet ()
 Get the currently active sheet.
 
 getBuiltInFormatCode ()
 Get Built-In Format Code.
 
 getFormatCode (bool $extended=false)
 Get Format Code.
 
 getHashCode ()
 Get hash code.
 
 getIsSupervisor ()
 Is this a supervisor or a cell style component?
 
 getSelectedCells ()
 Get the currently active cell coordinate in currently active sheet.
 
 getSharedComponent ()
 Get the shared style component for the currently active cell in currently active sheet.
 
 getStyleArray (array $array)
 Build style array from subcomponents.
 
 setBuiltInFormatCode (int $formatCodeIndex)
 Set Built-In Format Code.
 
 setFormatCode (string $formatCode)
 Set Format Code.
 

Static Public Member Functions

static builtInFormatCode (int $index)
 Get built-in format code.
 
static builtInFormatCodeIndex (string $formatCodeIndex)
 Get built-in format code index.
 
static convertSystemFormats (?string $formatCode)
 
static getDateTimeFormat ()
 
static getLongDateFormat ()
 
static getShortDateFormat ()
 
static getTimeFormat ()
 
static setDateTimeFormat (string $dateTimeFormat)
 
static setLongDateFormat (string $longDateFormat)
 
static setShortDateFormat (string $shortDateFormat)
 
static setTimeFormat (string $timeFormat)
 
static toFormattedString (mixed $value, string $format, ?array $callBack=null)
 Convert a value in a pre-defined format to a PHP string.
 

Public Attributes

const DATE_TIME_INDEX = 22
 
const DATE_TIME_OR_DATETIME_ARRAY
 
const FORMAT_ACCOUNTING_EUR = '_("€"* #,##0.00_);_("€"* (#,##0.00::);_("€"* "-"??_);_(@_)'
 
const FORMAT_ACCOUNTING_USD = '_("$"* #,##0.00_);_("$"* (#,##0.00::);_("$"* "-"??_);_(@_)'
 
const FORMAT_CURRENCY_EUR = '#,##0.00_-[$€]'
 
const FORMAT_CURRENCY_EUR_INTEGER = '#,##0_-[$€]'
 
const FORMAT_CURRENCY_USD = '$#,##0.00_-'
 
const FORMAT_CURRENCY_USD_INTEGER = '$#,##0_-'
 
const FORMAT_DATE_DATETIME = 'd/m/yy h:mm'
 
const FORMAT_DATE_DDMMYYYY = 'dd/mm/yyyy'
 
const FORMAT_DATE_DMMINUS = 'd-m'
 
const FORMAT_DATE_DMYMINUS = 'd-m-yy'
 
const FORMAT_DATE_DMYSLASH = 'd/m/yy'
 
const FORMAT_DATE_LONG_DATE = 'dddd, mmmm d, yyyy'
 
const FORMAT_DATE_MYMINUS = 'm-yy'
 
const FORMAT_DATE_TIME1 = 'h:mm AM/PM'
 
const FORMAT_DATE_TIME2 = 'h:mm:ss AM/PM'
 
const FORMAT_DATE_TIME3 = 'h:mm'
 
const FORMAT_DATE_TIME4 = 'h:mm:ss'
 
const FORMAT_DATE_TIME5 = 'mm:ss'
 
const FORMAT_DATE_TIME6 = 'h:mm:ss'
 
const FORMAT_DATE_TIME7 = 'i:s.S'
 
const FORMAT_DATE_TIME8 = 'h:mm:ss;@'
 
const FORMAT_DATE_XLSX14 = 'mm-dd-yy'
 
const FORMAT_DATE_XLSX14_ACTUAL = 'm/d/yyyy'
 
const FORMAT_DATE_XLSX15 = 'd-mmm-yy'
 
const FORMAT_DATE_XLSX16 = 'd-mmm'
 
const FORMAT_DATE_XLSX17 = 'mmm-yy'
 
const FORMAT_DATE_XLSX22 = 'm/d/yy h:mm'
 
const FORMAT_DATE_XLSX22_ACTUAL = 'm/d/yyyy h:mm'
 
const FORMAT_DATE_YYYYMMDD = 'yyyy-mm-dd'
 
const FORMAT_DATE_YYYYMMDDSLASH = 'yyyy/mm/dd;@'
 
const FORMAT_GENERAL = 'General'
 
const FORMAT_NUMBER = '0'
 
const FORMAT_NUMBER_0 = '0.0'
 
const FORMAT_NUMBER_00 = '0.00'
 
const FORMAT_NUMBER_COMMA_SEPARATED1 = '#,##0.00'
 
const FORMAT_NUMBER_COMMA_SEPARATED2 = '#,##0.00_-'
 
const FORMAT_PERCENTAGE = '0%'
 
const FORMAT_PERCENTAGE_0 = '0.0%'
 
const FORMAT_PERCENTAGE_00 = '0.00%'
 
const FORMAT_SYSDATE_F800 = '[$-F800]'
 
const FORMAT_SYSDATE_X = '[$-x-sysdate]'
 
const FORMAT_SYSTIME_F400 = '[$-F400]'
 
const FORMAT_SYSTIME_X = '[$-x-systime]'
 
const FORMAT_TEXT = '@'
 
const SHORT_DATE_INDEX = 14
 
const TIME_OR_DATETIME_ARRAY
 

Protected Member Functions

 exportArray1 ()
 Abstract method to be implemented in anything which extends this class.
 
 exportArray2 (array &$exportedArray, string $index, mixed $objOrValue)
 Populate array from exportArray1.
 

Protected Attributes

false int $builtInFormatCode = 0
 Built-in format Code.
 
string $formatCode = self::FORMAT_GENERAL
 Format Code.
 
bool $isSupervisor
 
Spreadsheet Supervisor $parent
 Parent.
 
string $parentPropertyName = null
 Parent property name.
 

Static Protected Attributes

static array $builtInFormats
 
static string $dateTimeFormat = self::FORMAT_DATE_XLSX22_ACTUAL
 
static array $flippedBuiltInFormats
 Excel built-in number formats (flipped, for faster lookups).
 
static string $longDateFormat = self::FORMAT_DATE_LONG_DATE
 
static string $shortDateFormat = self::FORMAT_DATE_XLSX14_ACTUAL
 
static string $timeFormat = self::FORMAT_DATE_TIME2
 

Constructor & Destructor Documentation

◆ __construct()

PhpOffice\PhpSpreadsheet\Style\NumberFormat::__construct ( bool $isSupervisor = false,
bool $isConditional = false )

Create a new NumberFormat.

Parameters
bool$isSupervisorFlag indicating if this is a supervisor or not Leave this value at default unless you understand exactly what its ramifications are
bool$isConditionalFlag indicating if this is a conditional style or not Leave this value at default unless you understand exactly what its ramifications are

Member Function Documentation

◆ __clone()

PhpOffice\PhpSpreadsheet\Style\Supervisor::__clone ( )
inherited

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

Reimplemented in PhpOffice\PhpSpreadsheet\Style\Font.

◆ applyFromArray()

PhpOffice\PhpSpreadsheet\Style\NumberFormat::applyFromArray ( array $styleArray)

Apply styles from array.

$spreadsheet->getActiveSheet()->getStyle('B2')->getNumberFormat()->applyFromArray( [ 'formatCode' => NumberFormat::FORMAT_CURRENCY_EUR_SIMPLE ] );

Parameters
array$styleArrayArray containing style information
Return values
$this

◆ bindParent()

PhpOffice\PhpSpreadsheet\Style\Supervisor::bindParent ( Spreadsheet|self $parent,
?string $parentPropertyName = null )
inherited

Bind parent.

Only used for supervisor.

Return values
$this

◆ builtInFormatCodeIndex()

static PhpOffice\PhpSpreadsheet\Style\NumberFormat::builtInFormatCodeIndex ( string $formatCodeIndex)
static

Get built-in format code index.

Return values
false|int

◆ exportArray()

PhpOffice\PhpSpreadsheet\Style\Supervisor::exportArray ( )
finalinherited

Export style as array.

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

◆ exportArray1()

PhpOffice\PhpSpreadsheet\Style\NumberFormat::exportArray1 ( )
protected

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.

Reimplemented from PhpOffice\PhpSpreadsheet\Style\Supervisor.

◆ exportArray2()

PhpOffice\PhpSpreadsheet\Style\Supervisor::exportArray2 ( array & $exportedArray,
string $index,
mixed $objOrValue )
finalprotectedinherited

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.

◆ getActiveCell()

PhpOffice\PhpSpreadsheet\Style\Supervisor::getActiveCell ( )
inherited

Get the currently active cell coordinate in currently active sheet.

Only used for supervisor.

Return values
stringE.g. 'A1'

◆ getActiveSheet()

PhpOffice\PhpSpreadsheet\Style\Supervisor::getActiveSheet ( )
inherited

Get the currently active sheet.

Only used for supervisor.

◆ getBuiltInFormatCode()

PhpOffice\PhpSpreadsheet\Style\NumberFormat::getBuiltInFormatCode ( )

Get Built-In Format Code.

Return values
false|int

◆ getHashCode()

PhpOffice\PhpSpreadsheet\Style\NumberFormat::getHashCode ( )

Get hash code.

Return values
stringHash code

Implements PhpOffice\PhpSpreadsheet\IComparable.

◆ getSelectedCells()

PhpOffice\PhpSpreadsheet\Style\Supervisor::getSelectedCells ( )
inherited

Get the currently active cell coordinate in currently active sheet.

Only used for supervisor.

Return values
stringE.g. 'A1'

◆ getSharedComponent()

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

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

Only used for style supervisor.

Reimplemented from PhpOffice\PhpSpreadsheet\Style\Supervisor.

◆ getStyleArray()

PhpOffice\PhpSpreadsheet\Style\NumberFormat::getStyleArray ( array $array)

Build style array from subcomponents.

Reimplemented from PhpOffice\PhpSpreadsheet\Style\Supervisor.

◆ setBuiltInFormatCode()

PhpOffice\PhpSpreadsheet\Style\NumberFormat::setBuiltInFormatCode ( int $formatCodeIndex)

Set Built-In Format Code.

Parameters
int$formatCodeIndexId of the built-in format code to use
Return values
$this

◆ setFormatCode()

PhpOffice\PhpSpreadsheet\Style\NumberFormat::setFormatCode ( string $formatCode)

Set Format Code.

Parameters
string$formatCodesee self::FORMAT_*
Return values
$this

◆ toFormattedString()

static PhpOffice\PhpSpreadsheet\Style\NumberFormat::toFormattedString ( mixed $value,
string $format,
?array $callBack = null )
static

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

Parameters
null | bool | float | int | RichText | string$valueValue to format
string$formatFormat code: see = self::FORMAT_* for predefined values; or can be any valid MS Excel custom format string
?array$callBackCallback function for additional formatting of string
Return values
stringFormatted string

Member Data Documentation

◆ $parent

Spreadsheet Supervisor PhpOffice\PhpSpreadsheet\Style\Supervisor::$parent
protectedinherited

Parent.

Only used for supervisor.

◆ DATE_TIME_OR_DATETIME_ARRAY

const PhpOffice\PhpSpreadsheet\Style\NumberFormat::DATE_TIME_OR_DATETIME_ARRAY
Initial value:
= [
self::FORMAT_DATE_YYYYMMDD,
self::FORMAT_DATE_DDMMYYYY,
self::FORMAT_DATE_DMYSLASH,
self::FORMAT_DATE_DMYMINUS,
self::FORMAT_DATE_DMMINUS,
self::FORMAT_DATE_MYMINUS,
self::FORMAT_DATE_XLSX14,
self::FORMAT_DATE_XLSX14_ACTUAL,
self::FORMAT_DATE_XLSX15,
self::FORMAT_DATE_XLSX16,
self::FORMAT_DATE_XLSX17,
self::FORMAT_DATE_XLSX22,
self::FORMAT_DATE_XLSX22_ACTUAL,
self::FORMAT_DATE_DATETIME,
self::FORMAT_DATE_TIME1,
self::FORMAT_DATE_TIME2,
self::FORMAT_DATE_TIME3,
self::FORMAT_DATE_TIME4,
self::FORMAT_DATE_TIME5,
self::FORMAT_DATE_TIME6,
self::FORMAT_DATE_TIME7,
self::FORMAT_DATE_TIME8,
self::FORMAT_DATE_YYYYMMDDSLASH,
self::FORMAT_DATE_LONG_DATE,
]

◆ TIME_OR_DATETIME_ARRAY

const PhpOffice\PhpSpreadsheet\Style\NumberFormat::TIME_OR_DATETIME_ARRAY
Initial value:
= [
self::FORMAT_DATE_XLSX22,
self::FORMAT_DATE_DATETIME,
self::FORMAT_DATE_TIME1,
self::FORMAT_DATE_TIME2,
self::FORMAT_DATE_TIME3,
self::FORMAT_DATE_TIME4,
self::FORMAT_DATE_TIME5,
self::FORMAT_DATE_TIME6,
self::FORMAT_DATE_TIME7,
self::FORMAT_DATE_TIME8,
]

The documentation for this class was generated from the following file: