You are here

public function PHPExcel_Reader_Excel2007::listWorksheetNames in Loft Data Grids 6.2

Same name and namespace in other branches
  1. 7.2 vendor/phpoffice/phpexcel/Classes/PHPExcel/Reader/Excel2007.php \PHPExcel_Reader_Excel2007::listWorksheetNames()

* Reads names of the worksheets from a file, without parsing the whole file to a PHPExcel object * *

Parameters

string $pFilename: * @throws PHPExcel_Reader_Exception

File

vendor/phpoffice/phpexcel/Classes/PHPExcel/Reader/Excel2007.php, line 123

Class

PHPExcel_Reader_Excel2007
PHPExcel_Reader_Excel2007

Code

public function listWorksheetNames($pFilename) {

  // Check if file exists
  if (!file_exists($pFilename)) {
    throw new PHPExcel_Reader_Exception("Could not open " . $pFilename . " for reading! File does not exist.");
  }
  $worksheetNames = array();
  $zipClass = PHPExcel_Settings::getZipClass();
  $zip = new $zipClass();
  $zip
    ->open($pFilename);

  //	The files we're looking at here are small enough that simpleXML is more efficient than XMLReader
  $rels = simplexml_load_string($this
    ->securityScan($this
    ->_getFromZipArchive($zip, "_rels/.rels"), 'SimpleXMLElement', PHPExcel_Settings::getLibXmlLoaderOptions()));

  //~ http://schemas.openxmlformats.org/package/2006/relationships");
  foreach ($rels->Relationship as $rel) {
    switch ($rel["Type"]) {
      case "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument":
        $xmlWorkbook = simplexml_load_string($this
          ->securityScan($this
          ->_getFromZipArchive($zip, "{$rel['Target']}"), 'SimpleXMLElement', PHPExcel_Settings::getLibXmlLoaderOptions()));

        //~ http://schemas.openxmlformats.org/spreadsheetml/2006/main");
        if ($xmlWorkbook->sheets) {
          foreach ($xmlWorkbook->sheets->sheet as $eleSheet) {

            // Check if sheet should be skipped
            $worksheetNames[] = (string) $eleSheet["name"];
          }
        }
    }
  }
  $zip
    ->close();
  return $worksheetNames;
}