diff --git a/Classes/PHPExcel/Reader/Gnumeric.php b/Classes/PHPExcel/Reader/Gnumeric.php index aae491d..f0863bc 100644 --- a/Classes/PHPExcel/Reader/Gnumeric.php +++ b/Classes/PHPExcel/Reader/Gnumeric.php @@ -222,6 +222,36 @@ class PHPExcel_Reader_Gnumeric implements PHPExcel_Reader_IReader return $data; } + /** + * Reads names of the worksheets from a file, without parsing the whole file to a PHPExcel object + * + * @param string $pFilename + * @throws Exception + */ + public function listWorksheetNames($pFilename) + { + // Check if file exists + if (!file_exists($pFilename)) { + throw new Exception("Could not open " . $pFilename . " for reading! File does not exist."); + } + + $gFileData = $this->_gzfileGetContents($pFilename); + + $xml = simplexml_load_string($gFileData); + $namespacesMeta = $xml->getNamespaces(true); + + $gnmXML = $xml->children($namespacesMeta['gnm']); + + $worksheetNames = array(); + + foreach($gnmXML->Sheets->Sheet as $sheet) { + $worksheetNames[] = (string) $sheet->Name; + } + + return $worksheetNames; + } + + /** * Loads PHPExcel from file into PHPExcel instance * diff --git a/Classes/PHPExcel/Reader/OOCalc.php b/Classes/PHPExcel/Reader/OOCalc.php index 8afdf42..20cd745 100644 --- a/Classes/PHPExcel/Reader/OOCalc.php +++ b/Classes/PHPExcel/Reader/OOCalc.php @@ -186,6 +186,42 @@ class PHPExcel_Reader_OOCalc implements PHPExcel_Reader_IReader return false; } + /** + * Reads names of the worksheets from a file, without parsing the whole file to a PHPExcel object + * + * @param string $pFilename + * @throws Exception + */ + public function listWorksheetNames($pFilename) + { + // Check if file exists + if (!file_exists($pFilename)) { + throw new Exception("Could not open " . $pFilename . " for reading! File does not exist."); + } + + $worksheetNames = array(); + + $zip = new ZipArchive; + if ($zip->open($pFilename) === true) { + + $xml = simplexml_load_string($zip->getFromName("content.xml")); + $namespacesContent = $xml->getNamespaces(true); + + $workbook = $xml->children($namespacesContent['office']); + foreach($workbook->body->spreadsheet as $workbookData) { + $workbookData = $workbookData->children($namespacesContent['table']); + foreach($workbookData->table as $worksheetDataSet) { + $worksheetDataAttributes = $worksheetDataSet->attributes($namespacesContent['table']); + + $worksheetNames[] = $worksheetDataAttributes['name']; + } + } + } + + return $worksheetNames; + } + + /** * Loads PHPExcel from file * diff --git a/changelog.txt b/changelog.txt index 3cb0f76..a81585f 100644 --- a/changelog.txt +++ b/changelog.txt @@ -26,7 +26,7 @@ Fixed in SVN: - Feature: (MBaker) Provide option to use PCLZip as an alternative to ZipArchive. This allows the writing of Excel2007 files, even without ZipArchive enabled (it does require zlib), or when php_zip is one of the buggy PHP 5.2.6 or 5.2.8 versions -- Feature: (MBaker) Work item 14979 - Added listWorksheetNames() method to Excel2007 and Excel5 Readers, allowing a user to extract a list of worksheet names from a file without parsing/loading the whole file. +- Feature: (MBaker) Work item 14979 - Added listWorksheetNames() method to Excel2007, Excel5, OOCalc and Gnumeric Readers, allowing a user to extract a list of worksheet names from a file without parsing/loading the whole file. - Bugfix: (MBaker) Work item 14888 - Simple =IF() formula disappears - Bugfix: (MBaker) Work item 14898 - PHP Warning: preg_match(): Compilation failed: PCRE does not support \\L, \\l, \\N, \\P, \\p, \\U, \\u, or \\X - Bugfix: (MBaker) Work item 14901 - VLOOKUP choking on parameters in PHPExcel.1.7.5/PHPExcel_Writer_Excel2007