You are here

public function PHPExcel_Reader_Gnumeric::listWorksheetInfo in Loft Data Grids 6.2

Same name and namespace in other branches
  1. 7.2 vendor/phpoffice/phpexcel/Classes/PHPExcel/Reader/Gnumeric.php \PHPExcel_Reader_Gnumeric::listWorksheetInfo()

* Return worksheet info (Name, Last Column Letter, Last Column Index, Total Rows, Total Columns) * *

Parameters

string $pFilename: * @throws PHPExcel_Reader_Exception

File

vendor/phpoffice/phpexcel/Classes/PHPExcel/Reader/Gnumeric.php, line 145

Class

PHPExcel_Reader_Gnumeric
PHPExcel_Reader_Gnumeric

Code

public function listWorksheetInfo($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);
  $worksheetInfo = array();
  while ($xml
    ->read()) {
    if ($xml->name == 'gnm:Sheet' && $xml->nodeType == XMLReader::ELEMENT) {
      $tmpInfo = array(
        'worksheetName' => '',
        'lastColumnLetter' => 'A',
        'lastColumnIndex' => 0,
        'totalRows' => 0,
        'totalColumns' => 0,
      );
      while ($xml
        ->read()) {
        if ($xml->name == 'gnm:Name' && $xml->nodeType == XMLReader::ELEMENT) {
          $xml
            ->read();

          //	Move onto the value node
          $tmpInfo['worksheetName'] = (string) $xml->value;
        }
        elseif ($xml->name == 'gnm:MaxCol' && $xml->nodeType == XMLReader::ELEMENT) {
          $xml
            ->read();

          //	Move onto the value node
          $tmpInfo['lastColumnIndex'] = (int) $xml->value;
          $tmpInfo['totalColumns'] = (int) $xml->value + 1;
        }
        elseif ($xml->name == 'gnm:MaxRow' && $xml->nodeType == XMLReader::ELEMENT) {
          $xml
            ->read();

          //	Move onto the value node
          $tmpInfo['totalRows'] = (int) $xml->value + 1;
          break;
        }
      }
      $tmpInfo['lastColumnLetter'] = PHPExcel_Cell::stringFromColumnIndex($tmpInfo['lastColumnIndex']);
      $worksheetInfo[] = $tmpInfo;
    }
  }
  return $worksheetInfo;
}