You are here

public function PHPExcel_Reader_Gnumeric::listWorksheetNames in Loft Data Grids 7.2

Same name and namespace in other branches
  1. 6.2 vendor/phpoffice/phpexcel/Classes/PHPExcel/Reader/Gnumeric.php \PHPExcel_Reader_Gnumeric::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/Gnumeric.php, line 111

Class

PHPExcel_Reader_Gnumeric
PHPExcel_Reader_Gnumeric

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.");
  }
  $xml = new XMLReader();
  $xml
    ->xml($this
    ->securityScanFile('compress.zlib://' . realpath($pFilename)), null, PHPExcel_Settings::getLibXmlLoaderOptions());
  $xml
    ->setParserProperty(2, true);
  $worksheetNames = array();
  while ($xml
    ->read()) {
    if ($xml->name == 'gnm:SheetName' && $xml->nodeType == XMLReader::ELEMENT) {
      $xml
        ->read();

      //	Move onto the value node
      $worksheetNames[] = (string) $xml->value;
    }
    elseif ($xml->name == 'gnm:Sheets') {

      //	break out of the loop once we've got our sheet names rather than parse the entire file
      break;
    }
  }
  return $worksheetNames;
}