Support for missing styles XML file in XLSX

Some files don't have a "styles.xml" file. Excel supports these files, Spout should do too.
This commit is contained in:
Adrien Loison authored and Adrien Loison committed 2019-07-20 16:48:51 +02:00
1 parent 6c4086cf97
commit 1bbfd45b82
5 files changed
+37 -3

No files matched your search

+12 -2
View File
@@ -48,7 +48,10 @@ class StyleManager
/** @var string Path of the XLSX file being read */
protected $filePath;
/** @var string Path of the styles XML file */
/** @var bool Whether the XLSX file contains a styles XML file */
protected $hasStylesXMLFile;
/** @var string|null Path of the styles XML file */
protected $stylesXMLFilePath;
/** @var InternalEntityFactory Factory to create entities */
@@ -76,7 +79,10 @@ class StyleManager
$this->filePath = $filePath;
$this->entityFactory = $entityFactory;
$this->builtinNumFmtIdIndicatingDates = array_keys(self::$builtinNumFmtIdToNumFormatMapping);
$this->stylesXMLFilePath = $workbookRelationshipsManager->getStylesXMLFilePath();
$this->hasStylesXMLFile = $workbookRelationshipsManager->hasStylesXMLFile();
if ($this->hasStylesXMLFile) {
$this->stylesXMLFilePath = $workbookRelationshipsManager->getStylesXMLFilePath();
}
}
/**
@@ -88,6 +94,10 @@ class StyleManager
*/
public function shouldFormatNumericValueAsDate($styleId)
{
if (!$this->hasStylesXMLFile) {
return false;
}
$stylesAttributes = $this->getStylesAttributes();
// Default style (0) does not format numeric values as timestamps. Only custom styles do.
@@ -75,7 +75,17 @@ class WorkbookRelationshipsManager
}
/**
* @return string|null The path of the styles XML file
* @return bool Whether the XLSX file contains a styles XML file
*/
public function hasStylesXMLFile()
{
$workbookRelationships = $this->getWorkbookRelationships();
return isset($workbookRelationships[self::RELATIONSHIP_TYPE_STYLES]);
}
/**
* @return string The path of the styles XML file
*/
public function getStylesXMLFilePath()
{