Moodle PHP Documentation 4.1
Moodle 4.1.19+ (Build: 20250711) (5f47dc23ffc)
Box\Spout\Reader\XLSX\Manager\StyleManager Class Reference

Public Member Functions

 __construct ($filePath, $workbookRelationshipsManager, $entityFactory)
 
 getNumberFormatCode ($styleId)
 Returns the format as defined in "styles.xml" of the given style.
 
 shouldFormatNumericValueAsDate ($styleId)
 Returns whether the style with the given ID should consider numeric values as timestamps and format the cell as a date.
 

Public Attributes

const DEFAULT_STYLE_ID = 0
 By convention, default style ID is 0.
 
const NUMBER_FORMAT_GENERAL = 'General'
 
const XML_ATTRIBUTE_APPLY_NUMBER_FORMAT = 'applyNumberFormat'
 
const XML_ATTRIBUTE_FORMAT_CODE = 'formatCode'
 
const XML_ATTRIBUTE_NUM_FMT_ID = 'numFmtId'
 Attributes used to find relevant information in the styles XML file.
 
const XML_NODE_CELL_XFS = 'cellXfs'
 
const XML_NODE_NUM_FMT = 'numFmt'
 
const XML_NODE_NUM_FMTS = 'numFmts'
 Nodes used to find relevant information in the styles XML file.
 
const XML_NODE_XF = 'xf'
 

Protected Member Functions

 doesNumFmtIdIndicateDate ($numFmtId)
 Returns whether the number format ID indicates that the number is a date.
 
 doesStyleIndicateDate ($styleAttributes)
 
 extractNumberFormats ($xmlReader)
 Extracts number formats from the "numFmt" nodes.
 
 extractRelevantInfo ()
 Reads the styles.xml file and extract the relevant information from the file.
 
 extractStyleAttributes ($xmlReader)
 Extracts style attributes from the "xf" nodes, inside the "cellXfs" section.
 
 getCustomNumberFormats ()
 
 getFormatCodeForNumFmtId ($numFmtId)
 
 getStylesAttributes ()
 
 isFormatCodeCustomDateFormat ($formatCode)
 
 isFormatCodeMatchingDateFormatPattern ($formatCode)
 
 isNumFmtIdBuiltInDateFormat ($numFmtId)
 

Protected Attributes

array $builtinNumFmtIdIndicatingDates
 Array containing the IDs of built-in number formats indicating a date.
 
array $customNumberFormats
 Array containing a mapping NUM_FMT_ID => FORMAT_CODE.
 
InternalEntityFactory $entityFactory
 Factory to create entities.
 
string $filePath
 Path of the XLSX file being read.
 
bool $hasStylesXMLFile
 Whether the XLSX file contains a styles XML file.
 
array $numFmtIdToIsDateFormatCache = []
 Cache containing a mapping NUM_FMT_ID => IS_DATE_FORMAT.
 
array $stylesAttributes
 Array containing a mapping STYLE_ID => [STYLE_ATTRIBUTES].
 
string null $stylesXMLFilePath
 Path of the styles XML file.
 

Static Protected Attributes

static array $builtinNumFmtIdToNumFormatMapping
 

Constructor & Destructor Documentation

◆ __construct()

Box\Spout\Reader\XLSX\Manager\StyleManager::__construct ( $filePath,
$workbookRelationshipsManager,
$entityFactory )
Parameters
string$filePathPath of the XLSX file being read
WorkbookRelationshipsManager$workbookRelationshipsManagerHelps retrieving workbook relationships
InternalEntityFactory$entityFactoryFactory to create entities

Member Function Documentation

◆ doesNumFmtIdIndicateDate()

Box\Spout\Reader\XLSX\Manager\StyleManager::doesNumFmtIdIndicateDate ( $numFmtId)
protected

Returns whether the number format ID indicates that the number is a date.

The result is cached to avoid recomputing the same thing over and over, as "numFmtId" attributes can be shared between multiple styles.

Parameters
int$numFmtId
Return values
boolWhether the number format ID indicates that the number is a date

◆ doesStyleIndicateDate()

Box\Spout\Reader\XLSX\Manager\StyleManager::doesStyleIndicateDate ( $styleAttributes)
protected
Parameters
array$styleAttributesArray containing the style attributes (2 keys: "applyNumberFormat" and "numFmtId")
Return values
boolWhether the style with the given attributes indicates that the number is a date

◆ extractNumberFormats()

Box\Spout\Reader\XLSX\Manager\StyleManager::extractNumberFormats ( $xmlReader)
protected

Extracts number formats from the "numFmt" nodes.

For simplicity, the styles attributes are kept in memory. This is possible thanks to the reuse of formats. So 1 million cells should not use 1 million formats.

Parameters
Box\Spout\Reader\Wrapper\XMLReader$xmlReaderXML Reader positioned on the "numFmts" node
Return values
void

◆ extractRelevantInfo()

Box\Spout\Reader\XLSX\Manager\StyleManager::extractRelevantInfo ( )
protected

Reads the styles.xml file and extract the relevant information from the file.

Return values
void

◆ extractStyleAttributes()

Box\Spout\Reader\XLSX\Manager\StyleManager::extractStyleAttributes ( $xmlReader)
protected

Extracts style attributes from the "xf" nodes, inside the "cellXfs" section.

For simplicity, the styles attributes are kept in memory. This is possible thanks to the reuse of styles. So 1 million cells should not use 1 million styles.

Parameters
Box\Spout\Reader\Wrapper\XMLReader$xmlReaderXML Reader positioned on the "cellXfs" node
Return values
void

◆ getCustomNumberFormats()

Box\Spout\Reader\XLSX\Manager\StyleManager::getCustomNumberFormats ( )
protected
Return values
arrayThe custom number formats

◆ getFormatCodeForNumFmtId()

Box\Spout\Reader\XLSX\Manager\StyleManager::getFormatCodeForNumFmtId ( $numFmtId)
protected
Parameters
int$numFmtId
Return values
string|nullThe custom number format or NULL if none defined for the given numFmtId

◆ getNumberFormatCode()

Box\Spout\Reader\XLSX\Manager\StyleManager::getNumberFormatCode ( $styleId)

Returns the format as defined in "styles.xml" of the given style.

NOTE: It is assumed that the style DOES have a number format associated to it.

Parameters
int$styleIdZero-based style ID
Return values
stringThe number format code associated with the given style

◆ getStylesAttributes()

Box\Spout\Reader\XLSX\Manager\StyleManager::getStylesAttributes ( )
protected
Return values
arrayThe styles attributes

◆ isFormatCodeCustomDateFormat()

Box\Spout\Reader\XLSX\Manager\StyleManager::isFormatCodeCustomDateFormat ( $formatCode)
protected
Parameters
string | null$formatCode
Return values
boolWhether the given format code indicates that the number is a date

◆ isFormatCodeMatchingDateFormatPattern()

Box\Spout\Reader\XLSX\Manager\StyleManager::isFormatCodeMatchingDateFormatPattern ( $formatCode)
protected
Parameters
string$formatCode
Return values
boolWhether the given format code matches a date format pattern

◆ isNumFmtIdBuiltInDateFormat()

Box\Spout\Reader\XLSX\Manager\StyleManager::isNumFmtIdBuiltInDateFormat ( $numFmtId)
protected
Parameters
int$numFmtId
Return values
boolWhether the number format ID indicates that the number is a date

◆ shouldFormatNumericValueAsDate()

Box\Spout\Reader\XLSX\Manager\StyleManager::shouldFormatNumericValueAsDate ( $styleId)

Returns whether the style with the given ID should consider numeric values as timestamps and format the cell as a date.

Parameters
int$styleIdZero-based style ID
Return values
boolWhether the cell with the given cell should display a date instead of a numeric value

Member Data Documentation

◆ $builtinNumFmtIdToNumFormatMapping

array Box\Spout\Reader\XLSX\Manager\StyleManager::$builtinNumFmtIdToNumFormatMapping
staticprotected
Initial value:
= [
14 => 'm/d/yyyy',
15 => 'd-mmm-yy',
16 => 'd-mmm',
17 => 'mmm-yy',
18 => 'h:mm AM/PM',
19 => 'h:mm:ss AM/PM',
20 => 'h:mm',
21 => 'h:mm:ss',
22 => 'm/d/yyyy h:mm',
45 => 'mm:ss',
46 => '[h]:mm:ss',
47 => 'mm:ss.0',
]
See also
https://msdn.microsoft.com/en-us/library/ff529597(v=office.12).aspx Mapping between built-in numFmtId and the associated format - for dates only

◆ $numFmtIdToIsDateFormatCache

array Box\Spout\Reader\XLSX\Manager\StyleManager::$numFmtIdToIsDateFormatCache = []
protected

Cache containing a mapping NUM_FMT_ID => IS_DATE_FORMAT.

Used to avoid lots of recalculations


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