PHP Class Box\Spout\Reader\XLSX\Helper\StyleHelper

Datei anzeigen Open project: box/spout

Protected Properties

Property Type Description
$builtinNumFmtIdIndicatingDates Array containing the IDs of built-in number formats indicating a date
$builtinNumFmtIdToNumFormatMapping Mapping between built-in numFmtId and the associated format - for dates only
$customNumberFormats Array containing a mapping NUM_FMT_ID => FORMAT_CODE
$filePath Path of the XLSX file being read
$numFmtIdToIsDateFormatCache Cache containing a mapping NUM_FMT_ID => IS_DATE_FORMAT. Used to avoid lots of recalculations
$stylesAttributes Array containing a mapping STYLE_ID => [STYLE_ATTRIBUTES]

Public Methods

Method Description
__construct ( string $filePath )
getNumberFormatCode ( integer $styleId ) : string Returns the format as defined in "styles.xml" of the given style.
shouldFormatNumericValueAsDate ( integer $styleId ) : boolean Returns whether the style with the given ID should consider numeric values as timestamps and format the cell as a date.

Protected Methods

Method Description
doesNumFmtIdIndicateDate ( integer $numFmtId ) : boolean Returns whether the number format ID indicates that the number is a date.
doesStyleIndicateDate ( array $styleAttributes ) : boolean
extractNumberFormats ( Box\Spout\Reader\Wrapper\XMLReader $xmlReader ) : void Extracts number formats from the "numFmt" nodes.
extractRelevantInfo ( ) : void Reads the styles.xml file and extract the relevant information from the file.
extractStyleAttributes ( Box\Spout\Reader\Wrapper\XMLReader $xmlReader ) : void Extracts style attributes from the "xf" nodes, inside the "cellXfs" section.
getCustomNumberFormats ( ) : array
getFormatCodeForNumFmtId ( integer $numFmtId ) : string | null
getStylesAttributes ( ) : array
isFormatCodeCustomDateFormat ( string | null $formatCode ) : boolean
isFormatCodeMatchingDateFormatPattern ( string $formatCode ) : boolean
isNumFmtIdBuiltInDateFormat ( integer $numFmtId ) : boolean

Method Details

__construct() public method

public __construct ( string $filePath )
$filePath string Path of the XLSX file being read

doesNumFmtIdIndicateDate() protected method

The result is cached to avoid recomputing the same thing over and over, as "numFmtId" attributes can be shared between multiple styles.
protected doesNumFmtIdIndicateDate ( integer $numFmtId ) : boolean
$numFmtId integer
return boolean Whether the number format ID indicates that the number is a date

doesStyleIndicateDate() protected method

protected doesStyleIndicateDate ( array $styleAttributes ) : boolean
$styleAttributes array Array containing the style attributes (2 keys: "applyNumberFormat" and "numFmtId")
return boolean Whether the style with the given attributes indicates that the number is a date

extractNumberFormats() protected method

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.
protected extractNumberFormats ( Box\Spout\Reader\Wrapper\XMLReader $xmlReader ) : void
$xmlReader Box\Spout\Reader\Wrapper\XMLReader XML Reader positioned on the "numFmts" node
return void

extractRelevantInfo() protected method

Reads the styles.xml file and extract the relevant information from the file.
protected extractRelevantInfo ( ) : void
return void

extractStyleAttributes() protected method

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.
protected extractStyleAttributes ( Box\Spout\Reader\Wrapper\XMLReader $xmlReader ) : void
$xmlReader Box\Spout\Reader\Wrapper\XMLReader XML Reader positioned on the "cellXfs" node
return void

getCustomNumberFormats() protected method

protected getCustomNumberFormats ( ) : array
return array The custom number formats

getFormatCodeForNumFmtId() protected method

protected getFormatCodeForNumFmtId ( integer $numFmtId ) : string | null
$numFmtId integer
return string | null The custom number format or NULL if none defined for the given numFmtId

getNumberFormatCode() public method

NOTE: It is assumed that the style DOES have a number format associated to it.
public getNumberFormatCode ( integer $styleId ) : string
$styleId integer Zero-based style ID
return string The number format code associated with the given style

getStylesAttributes() protected method

protected getStylesAttributes ( ) : array
return array The styles attributes

isFormatCodeCustomDateFormat() protected method

protected isFormatCodeCustomDateFormat ( string | null $formatCode ) : boolean
$formatCode string | null
return boolean Whether the given format code indicates that the number is a date

isFormatCodeMatchingDateFormatPattern() protected method

protected isFormatCodeMatchingDateFormatPattern ( string $formatCode ) : boolean
$formatCode string
return boolean Whether the given format code matches a date format pattern

isNumFmtIdBuiltInDateFormat() protected method

protected isNumFmtIdBuiltInDateFormat ( integer $numFmtId ) : boolean
$numFmtId integer
return boolean Whether the number format ID indicates that the number is a date

shouldFormatNumericValueAsDate() public method

Returns whether the style with the given ID should consider numeric values as timestamps and format the cell as a date.
public shouldFormatNumericValueAsDate ( integer $styleId ) : boolean
$styleId integer Zero-based style ID
return boolean Whether the cell with the given cell should display a date instead of a numeric value

Property Details

$builtinNumFmtIdIndicatingDates protected_oe property

Array containing the IDs of built-in number formats indicating a date
protected $builtinNumFmtIdIndicatingDates

$builtinNumFmtIdToNumFormatMapping protected_oe static_oe property

Mapping between built-in numFmtId and the associated format - for dates only
See also: https://msdn.microsoft.com/en-us/library/ff529597(v=office.12).aspx
protected static $builtinNumFmtIdToNumFormatMapping

$customNumberFormats protected_oe property

Array containing a mapping NUM_FMT_ID => FORMAT_CODE
protected $customNumberFormats

$filePath protected_oe property

Path of the XLSX file being read
protected $filePath

$numFmtIdToIsDateFormatCache protected_oe property

Cache containing a mapping NUM_FMT_ID => IS_DATE_FORMAT. Used to avoid lots of recalculations
protected $numFmtIdToIsDateFormatCache

$stylesAttributes protected_oe property

Array containing a mapping STYLE_ID => [STYLE_ATTRIBUTES]
protected $stylesAttributes