You are here

public function PHPExcel_Reader_OOCalc::listWorksheetNames in Loft Data Grids 6.2

Same name and namespace in other branches
  1. 7.2 vendor/phpoffice/phpexcel/Classes/PHPExcel/Reader/OOCalc.php \PHPExcel_Reader_OOCalc::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/OOCalc.php, line 122

Class

PHPExcel_Reader_OOCalc
PHPExcel_Reader_OOCalc

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.");
  }
  $zipClass = PHPExcel_Settings::getZipClass();
  $zip = new $zipClass();
  if (!$zip
    ->open($pFilename)) {
    throw new PHPExcel_Reader_Exception("Could not open " . $pFilename . " for reading! Error opening file.");
  }
  $worksheetNames = array();
  $xml = new XMLReader();
  $res = $xml
    ->xml($this
    ->securityScanFile('zip://' . realpath($pFilename) . '#content.xml'), null, PHPExcel_Settings::getLibXmlLoaderOptions());
  $xml
    ->setParserProperty(2, true);

  //	Step into the first level of content of the XML
  $xml
    ->read();
  while ($xml
    ->read()) {

    //	Quickly jump through to the office:body node
    while ($xml->name !== 'office:body') {
      if ($xml->isEmptyElement) {
        $xml
          ->read();
      }
      else {
        $xml
          ->next();
      }
    }

    //	Now read each node until we find our first table:table node
    while ($xml
      ->read()) {
      if ($xml->name == 'table:table' && $xml->nodeType == XMLReader::ELEMENT) {

        //	Loop through each table:table node reading the table:name attribute for each worksheet name
        do {
          $worksheetNames[] = $xml
            ->getAttribute('table:name');
          $xml
            ->next();
        } while ($xml->name == 'table:table' && $xml->nodeType == XMLReader::ELEMENT);
      }
    }
  }
  return $worksheetNames;
}