You are here

function PHPExcel_Writer_Excel5_Parser::_cellToRowcol 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::_cellToRowcol()

* Convert an Excel cell reference such as A1 or $B2 or C$3 or $D$4 to a zero * indexed row and column number. Also returns two (0,1) values to indicate * whether the row or column are relative references. * * @access private *

Parameters

string $cell The Excel cell reference in A1 format.: * @return array

1 call to PHPExcel_Writer_Excel5_Parser::_cellToRowcol()
PHPExcel_Writer_Excel5_Parser::_cellToPackedRowcol in vendor/phpoffice/phpexcel/Classes/PHPExcel/Writer/Excel5/Parser.php
* pack() row and column into the required 3 or 4 byte format. * * @access private *

File

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

Class

PHPExcel_Writer_Excel5_Parser
PHPExcel_Writer_Excel5_Parser

Code

function _cellToRowcol($cell) {
  preg_match('/(\\$)?([A-I]?[A-Z])(\\$)?(\\d+)/', $cell, $match);

  // return absolute column if there is a $ in the ref
  $col_rel = empty($match[1]) ? 1 : 0;
  $col_ref = $match[2];
  $row_rel = empty($match[3]) ? 1 : 0;
  $row = $match[4];

  // Convert base26 column string to a number.
  $expn = strlen($col_ref) - 1;
  $col = 0;
  $col_ref_length = strlen($col_ref);
  for ($i = 0; $i < $col_ref_length; ++$i) {
    $col += (ord($col_ref[$i]) - 64) * pow(26, $expn);
    --$expn;
  }

  // Convert 1-index to zero-index
  --$row;
  --$col;
  return array(
    $row,
    $col,
    $row_rel,
    $col_rel,
  );
}