@@ -77,34 +77,17 @@ public function canRead($pFilename)
7777 {
7878 File::assertFile ($ pFilename );
7979
80- $ xl = false ;
81- // Load file
80+ $ result = false ;
8281 $ zip = new ZipArchive ();
82+
8383 if ($ zip ->open ($ pFilename ) === true ) {
84- // check if it is an OOXML archive
85- $ rels = simplexml_load_string (
86- $ this ->securityScanner ->scan (
87- $ this ->getFromZipArchive ($ zip , '_rels/.rels ' )
88- ),
89- 'SimpleXMLElement ' ,
90- Settings::getLibXmlLoaderOptions ()
91- );
92- if ($ rels !== false ) {
93- foreach ($ rels ->Relationship as $ rel ) {
94- switch ($ rel ['Type ' ]) {
95- case 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument ' :
96- if (basename ($ rel ['Target ' ]) == 'workbook.xml ' ) {
97- $ xl = true ;
98- }
84+ $ workbookBasename = $ this ->getWorkbookBaseName ($ zip );
85+ $ result = !empty ($ workbookBasename );
9986
100- break ;
101- }
102- }
103- }
10487 $ zip ->close ();
10588 }
10689
107- return $ xl ;
90+ return $ result ;
10891 }
10992
11093 /**
@@ -357,8 +340,9 @@ public function load($pFilename)
357340
358341 // Read the theme first, because we need the colour scheme when reading the styles
359342 //~ http://schemas.openxmlformats.org/package/2006/relationships"
343+ $ workbookBasename = $ this ->getWorkbookBaseName ($ zip );
360344 $ wbRels = simplexml_load_string (
361- $ this ->securityScanner ->scan ($ this ->getFromZipArchive ($ zip , ' xl/_rels/workbook.xml. rels ' )),
345+ $ this ->securityScanner ->scan ($ this ->getFromZipArchive ($ zip , " xl/_rels/ $ {workbookBasename} . rels" )),
362346 'SimpleXMLElement ' ,
363347 Settings::getLibXmlLoaderOptions ()
364348 );
@@ -2026,4 +2010,38 @@ private function castXsdBooleanToBool($xsdBoolean)
20262010
20272011 return (bool ) $ xsdBoolean ;
20282012 }
2013+
2014+ /**
2015+ * @param ZipArchive $zip Opened zip archive
2016+ *
2017+ * @return string basename of the used excel workbook
2018+ */
2019+ private function getWorkbookBaseName (ZipArchive $ zip )
2020+ {
2021+ $ workbookBasename = '' ;
2022+
2023+ // check if it is an OOXML archive
2024+ $ rels = simplexml_load_string (
2025+ $ this ->securityScanner ->scan (
2026+ $ this ->getFromZipArchive ($ zip , '_rels/.rels ' )
2027+ ),
2028+ 'SimpleXMLElement ' ,
2029+ Settings::getLibXmlLoaderOptions ()
2030+ );
2031+ if ($ rels !== false ) {
2032+ foreach ($ rels ->Relationship as $ rel ) {
2033+ switch ($ rel ['Type ' ]) {
2034+ case 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument ' :
2035+ $ basename = basename ($ rel ['Target ' ]);
2036+ if (preg_match ('/workbook.*\.xml/ ' , $ basename )) {
2037+ $ workbookBasename = $ basename ;
2038+ }
2039+
2040+ break ;
2041+ }
2042+ }
2043+ }
2044+
2045+ return $ workbookBasename ;
2046+ }
20292047}
0 commit comments