You are here

public static function PHPExcel_Cell::columnIndexFromString in Loft Data Grids 6.2

Same name and namespace in other branches
  1. 7.2 vendor/phpoffice/phpexcel/Classes/PHPExcel/Cell.php \PHPExcel_Cell::columnIndexFromString()

* Column index from string * *

Parameters

string $pString: * @return int Column index (base 1 !!!)

57 calls to PHPExcel_Cell::columnIndexFromString()
PHPExcel_CachedObjectStorage_CacheBase::getHighestColumn in vendor/phpoffice/phpexcel/Classes/PHPExcel/CachedObjectStorage/CacheBase.php
* Get highest worksheet column *
PHPExcel_Calculation::_processTokenStack in vendor/phpoffice/phpexcel/Classes/PHPExcel/Calculation.php
PHPExcel_Calculation_LookupRef::COLUMN in vendor/phpoffice/phpexcel/Classes/PHPExcel/Calculation/LookupRef.php
* COLUMN * * Returns the column number of the given cell reference * If the cell reference is a range of cells, COLUMN returns the column numbers of each column in the reference as a horizontal array. * If cell reference is omitted, and the…
PHPExcel_Calculation_LookupRef::OFFSET in vendor/phpoffice/phpexcel/Classes/PHPExcel/Calculation/LookupRef.php
* OFFSET * * Returns a reference to a range that is a specified number of rows and columns from a cell or range of cells. * The reference that is returned can be a single cell or a range of cells. You can specify the number of rows and * the…
PHPExcel_Cell::compareCells in vendor/phpoffice/phpexcel/Classes/PHPExcel/Cell.php
* Compare 2 cells * *

... See full list

File

vendor/phpoffice/phpexcel/Classes/PHPExcel/Cell.php, line 782

Class

PHPExcel_Cell
PHPExcel_Cell

Code

public static function columnIndexFromString($pString = 'A') {

  //	Using a lookup cache adds a slight memory overhead, but boosts speed
  //	caching using a static within the method is faster than a class static,
  //		though it's additional memory overhead
  static $_indexCache = array();
  if (isset($_indexCache[$pString])) {
    return $_indexCache[$pString];
  }

  //	It's surprising how costly the strtoupper() and ord() calls actually are, so we use a lookup array rather than use ord()
  //		and make it case insensitive to get rid of the strtoupper() as well. Because it's a static, there's no significant
  //		memory overhead either
  static $_columnLookup = array(
    'A' => 1,
    'B' => 2,
    'C' => 3,
    'D' => 4,
    'E' => 5,
    'F' => 6,
    'G' => 7,
    'H' => 8,
    'I' => 9,
    'J' => 10,
    'K' => 11,
    'L' => 12,
    'M' => 13,
    'N' => 14,
    'O' => 15,
    'P' => 16,
    'Q' => 17,
    'R' => 18,
    'S' => 19,
    'T' => 20,
    'U' => 21,
    'V' => 22,
    'W' => 23,
    'X' => 24,
    'Y' => 25,
    'Z' => 26,
    'a' => 1,
    'b' => 2,
    'c' => 3,
    'd' => 4,
    'e' => 5,
    'f' => 6,
    'g' => 7,
    'h' => 8,
    'i' => 9,
    'j' => 10,
    'k' => 11,
    'l' => 12,
    'm' => 13,
    'n' => 14,
    'o' => 15,
    'p' => 16,
    'q' => 17,
    'r' => 18,
    's' => 19,
    't' => 20,
    'u' => 21,
    'v' => 22,
    'w' => 23,
    'x' => 24,
    'y' => 25,
    'z' => 26,
  );

  //	We also use the language construct isset() rather than the more costly strlen() function to match the length of $pString
  //		for improved performance
  if (isset($pString[0])) {
    if (!isset($pString[1])) {
      $_indexCache[$pString] = $_columnLookup[$pString];
      return $_indexCache[$pString];
    }
    elseif (!isset($pString[2])) {
      $_indexCache[$pString] = $_columnLookup[$pString[0]] * 26 + $_columnLookup[$pString[1]];
      return $_indexCache[$pString];
    }
    elseif (!isset($pString[3])) {
      $_indexCache[$pString] = $_columnLookup[$pString[0]] * 676 + $_columnLookup[$pString[1]] * 26 + $_columnLookup[$pString[2]];
      return $_indexCache[$pString];
    }
  }
  throw new PHPExcel_Exception("Column string index can not be " . (isset($pString[0]) ? "longer than 3 characters" : "empty"));
}