You are here

public function PHPExcel_Reader_Excel5::listWorksheetInfo in Loft Data Grids 7.2

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

Class

PHPExcel_Reader_Excel5
PHPExcel_Reader_Excel5

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.");
  }
  $worksheetInfo = array();

  // Read the OLE file
  $this
    ->_loadOLE($pFilename);

  // total byte size of Excel data (workbook global substream + sheet substreams)
  $this->_dataSize = strlen($this->_data);

  // initialize
  $this->_pos = 0;
  $this->_sheets = array();

  // Parse Workbook Global Substream
  while ($this->_pos < $this->_dataSize) {
    $code = self::_GetInt2d($this->_data, $this->_pos);
    switch ($code) {
      case self::XLS_Type_BOF:
        $this
          ->_readBof();
        break;
      case self::XLS_Type_SHEET:
        $this
          ->_readSheet();
        break;
      case self::XLS_Type_EOF:
        $this
          ->_readDefault();
        break 2;
      default:
        $this
          ->_readDefault();
        break;
    }
  }

  // Parse the individual sheets
  foreach ($this->_sheets as $sheet) {
    if ($sheet['sheetType'] != 0x0) {

      // 0x00: Worksheet
      // 0x02: Chart
      // 0x06: Visual Basic module
      continue;
    }
    $tmpInfo = array();
    $tmpInfo['worksheetName'] = $sheet['name'];
    $tmpInfo['lastColumnLetter'] = 'A';
    $tmpInfo['lastColumnIndex'] = 0;
    $tmpInfo['totalRows'] = 0;
    $tmpInfo['totalColumns'] = 0;
    $this->_pos = $sheet['offset'];
    while ($this->_pos <= $this->_dataSize - 4) {
      $code = self::_GetInt2d($this->_data, $this->_pos);
      switch ($code) {
        case self::XLS_Type_RK:
        case self::XLS_Type_LABELSST:
        case self::XLS_Type_NUMBER:
        case self::XLS_Type_FORMULA:
        case self::XLS_Type_BOOLERR:
        case self::XLS_Type_LABEL:
          $length = self::_GetInt2d($this->_data, $this->_pos + 2);
          $recordData = $this
            ->_readRecordData($this->_data, $this->_pos + 4, $length);

          // move stream pointer to next record
          $this->_pos += 4 + $length;
          $rowIndex = self::_GetInt2d($recordData, 0) + 1;
          $columnIndex = self::_GetInt2d($recordData, 2);
          $tmpInfo['totalRows'] = max($tmpInfo['totalRows'], $rowIndex);
          $tmpInfo['lastColumnIndex'] = max($tmpInfo['lastColumnIndex'], $columnIndex);
          break;
        case self::XLS_Type_BOF:
          $this
            ->_readBof();
          break;
        case self::XLS_Type_EOF:
          $this
            ->_readDefault();
          break 2;
        default:
          $this
            ->_readDefault();
          break;
      }
    }
    $tmpInfo['lastColumnLetter'] = PHPExcel_Cell::stringFromColumnIndex($tmpInfo['lastColumnIndex']);
    $tmpInfo['totalColumns'] = $tmpInfo['lastColumnIndex'] + 1;
    $worksheetInfo[] = $tmpInfo;
  }
  return $worksheetInfo;
}