You are here

function PHPExcel_Writer_Excel5_Parser::_getRefIndex in Loft Data Grids 6.2

Same name and namespace in other branches
  1. 7.2 vendor/phpoffice/phpexcel/Classes/PHPExcel/Writer/Excel5/Parser.php \PHPExcel_Writer_Excel5_Parser::_getRefIndex()

* Look up the REF index that corresponds to an external sheet name * (or range). If it doesn't exist yet add it to the workbook's references * array. It assumes all sheet names given must exist. * * @access private *

Parameters

string $ext_ref The name of the external reference: * @return mixed The reference index in packed() format on success

2 calls to PHPExcel_Writer_Excel5_Parser::_getRefIndex()
PHPExcel_Writer_Excel5_Parser::_convertRange3d in vendor/phpoffice/phpexcel/Classes/PHPExcel/Writer/Excel5/Parser.php
* Convert an Excel 3d range such as "Sheet1!A1:D4" or "Sheet1:Sheet2!A1:D4" to * a ptgArea3d. * * @access private *
PHPExcel_Writer_Excel5_Parser::_convertRef3d in vendor/phpoffice/phpexcel/Classes/PHPExcel/Writer/Excel5/Parser.php
* Convert an Excel 3d reference such as "Sheet1!A1" or "Sheet1:Sheet2!A1" to a * ptgRef3d. * * @access private *

File

vendor/phpoffice/phpexcel/Classes/PHPExcel/Writer/Excel5/Parser.php, line 849

Class

PHPExcel_Writer_Excel5_Parser
PHPExcel_Writer_Excel5_Parser

Code

function _getRefIndex($ext_ref) {
  $ext_ref = preg_replace("/^'/", '', $ext_ref);

  // Remove leading  ' if any.
  $ext_ref = preg_replace("/'\$/", '', $ext_ref);

  // Remove trailing ' if any.
  $ext_ref = str_replace('\'\'', '\'', $ext_ref);

  // Replace escaped '' with '
  // Check if there is a sheet range eg., Sheet1:Sheet2.
  if (preg_match("/:/", $ext_ref)) {
    list($sheet_name1, $sheet_name2) = explode(':', $ext_ref);
    $sheet1 = $this
      ->_getSheetIndex($sheet_name1);
    if ($sheet1 == -1) {
      throw new PHPExcel_Writer_Exception("Unknown sheet name {$sheet_name1} in formula");
    }
    $sheet2 = $this
      ->_getSheetIndex($sheet_name2);
    if ($sheet2 == -1) {
      throw new PHPExcel_Writer_Exception("Unknown sheet name {$sheet_name2} in formula");
    }

    // Reverse max and min sheet numbers if necessary
    if ($sheet1 > $sheet2) {
      list($sheet1, $sheet2) = array(
        $sheet2,
        $sheet1,
      );
    }
  }
  else {

    // Single sheet name only.
    $sheet1 = $this
      ->_getSheetIndex($ext_ref);
    if ($sheet1 == -1) {
      throw new PHPExcel_Writer_Exception("Unknown sheet name {$ext_ref} in formula");
    }
    $sheet2 = $sheet1;
  }

  // assume all references belong to this document
  $supbook_index = 0x0;
  $ref = pack('vvv', $supbook_index, $sheet1, $sheet2);
  $total_references = count($this->_references);
  $index = -1;
  for ($i = 0; $i < $total_references; ++$i) {
    if ($ref == $this->_references[$i]) {
      $index = $i;
      break;
    }
  }

  // if REF was not found add it to references array
  if ($index == -1) {
    $this->_references[$total_references] = $ref;
    $index = $total_references;
  }
  return pack('v', $index);
}