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

Datei anzeigen Open project: box/spout Class Usage Examples

Protected Properties

Property Type Description
$cachingStrategy The best caching strategy for storing shared strings
$filePath Path of the XLSX file being read
$tempFolder Temporary folder where the temporary files to store shared strings will be stored

Public Methods

Method Description
__construct ( string $filePath, string | null | void $tempFolder = null )
cleanup ( ) : void Destroys the cache, freeing memory and removing any created artifacts
extractSharedStrings ( ) : void Builds an in-memory array containing all the shared strings of the sheet.
getStringAtIndex ( integer $sharedStringIndex ) : string Returns the shared string at the given index, using the previously chosen caching strategy.
hasSharedStrings ( ) : boolean Returns whether the XLSX file contains a shared strings XML file

Protected Methods

Method Description
extractTextValueForNodes ( array $textNodes ) : string
getBestSharedStringsCachingStrategy ( integer | null $sharedStringsUniqueCount ) : Box\Spout\Reader\XLSX\Helper\SharedStringsCaching\CachingStrategyInterface Returns the best shared strings caching strategy.
getSharedStringsFilePath ( ) : string
getSharedStringsUniqueCount ( Box\Spout\Reader\Wrapper\XMLReader $xmlReader ) : integer | null Returns the shared strings unique count, as specified in tag.
getSimpleXmlElementNodeFromXMLReader ( Box\Spout\Reader\Wrapper\XMLReader $xmlReader ) : SimpleXMLElement Returns a SimpleXMLElement node from the current node in the given XMLReader instance.
processSharedStringsItem ( Box\Spout\Reader\Wrapper\XMLReader $xmlReader, integer $sharedStringIndex, Box\Spout\Common\Escaper\XLSX $escaper ) : void Processes the shared strings item XML node which the given XML reader is positioned on.
removeSuperfluousTextNodes ( SimpleXMLElement $parentNode ) : SimpleXMLElement Removes nodes that should not be read, like the pronunciation of the Kanji characters.
shouldPreserveWhitespace ( SimpleXMLElement $textNode ) : boolean If the text node has the attribute 'xml:space="preserve"', then preserve whitespace.

Method Details

__construct() public method

public __construct ( string $filePath, string | null | void $tempFolder = null )
$filePath string Path of the XLSX file being read
$tempFolder string | null | void Temporary folder where the temporary files to store shared strings will be stored

cleanup() public method

Destroys the cache, freeing memory and removing any created artifacts
public cleanup ( ) : void
return void

extractSharedStrings() public method

All the strings are stored in a XML file, located at 'xl/sharedStrings.xml'. It is then accessed by the sheet data, via the string index in the built table. More documentation available here: http://msdn.microsoft.com/en-us/library/office/gg278314.aspx The XML file can be really big with sheets containing a lot of data. That is why we need to use a XML reader that provides streaming like the XMLReader library. Please note that SimpleXML does not provide such a functionality but since it is faster and more handy to parse few XML nodes, it is used in combination with XMLReader for that purpose.
public extractSharedStrings ( ) : void
return void

extractTextValueForNodes() protected method

protected extractTextValueForNodes ( array $textNodes ) : string
$textNodes array Text XML nodes ("")
return string The value associated with the given text node(s)

getBestSharedStringsCachingStrategy() protected method

Returns the best shared strings caching strategy.
protected getBestSharedStringsCachingStrategy ( integer | null $sharedStringsUniqueCount ) : Box\Spout\Reader\XLSX\Helper\SharedStringsCaching\CachingStrategyInterface
$sharedStringsUniqueCount integer | null Number of unique shared strings (NULL if unknown)
return Box\Spout\Reader\XLSX\Helper\SharedStringsCaching\CachingStrategyInterface

getSharedStringsFilePath() protected method

protected getSharedStringsFilePath ( ) : string
return string The path to the shared strings XML file

getSharedStringsUniqueCount() protected method

Returns the shared strings unique count, as specified in tag.
protected getSharedStringsUniqueCount ( Box\Spout\Reader\Wrapper\XMLReader $xmlReader ) : integer | null
$xmlReader Box\Spout\Reader\Wrapper\XMLReader XMLReader instance
return integer | null Number of unique shared strings in the sharedStrings.xml file

getSimpleXmlElementNodeFromXMLReader() protected method

This is to simplify the parsing of the subtree.
protected getSimpleXmlElementNodeFromXMLReader ( Box\Spout\Reader\Wrapper\XMLReader $xmlReader ) : SimpleXMLElement
$xmlReader Box\Spout\Reader\Wrapper\XMLReader
return Box\Spout\Reader\Wrapper\SimpleXMLElement

getStringAtIndex() public method

Returns the shared string at the given index, using the previously chosen caching strategy.
public getStringAtIndex ( integer $sharedStringIndex ) : string
$sharedStringIndex integer Index of the shared string in the sharedStrings.xml file
return string The shared string at the given index

hasSharedStrings() public method

Returns whether the XLSX file contains a shared strings XML file
public hasSharedStrings ( ) : boolean
return boolean

processSharedStringsItem() protected method

Processes the shared strings item XML node which the given XML reader is positioned on.
protected processSharedStringsItem ( Box\Spout\Reader\Wrapper\XMLReader $xmlReader, integer $sharedStringIndex, Box\Spout\Common\Escaper\XLSX $escaper ) : void
$xmlReader Box\Spout\Reader\Wrapper\XMLReader
$sharedStringIndex integer Index of the processed shared strings item
$escaper Box\Spout\Common\Escaper\XLSX Helper to escape values
return void

removeSuperfluousTextNodes() protected method

By keeping them, their text content would be added to the read string.
protected removeSuperfluousTextNodes ( SimpleXMLElement $parentNode ) : SimpleXMLElement
$parentNode Box\Spout\Reader\Wrapper\SimpleXMLElement Parent node that may contain nodes to remove
return Box\Spout\Reader\Wrapper\SimpleXMLElement Cleaned parent node

shouldPreserveWhitespace() protected method

If the text node has the attribute 'xml:space="preserve"', then preserve whitespace.
protected shouldPreserveWhitespace ( SimpleXMLElement $textNode ) : boolean
$textNode Box\Spout\Reader\Wrapper\SimpleXMLElement The text node element () whitespace may be preserved
return boolean Whether whitespace should be preserved

Property Details

$cachingStrategy protected_oe property

The best caching strategy for storing shared strings
protected $cachingStrategy

$filePath protected_oe property

Path of the XLSX file being read
protected $filePath

$tempFolder protected_oe property

Temporary folder where the temporary files to store shared strings will be stored
protected $tempFolder