You are here

public static function PHPExcel_Calculation_LookupRef::COLUMN in Loft Data Grids 6.2

Same name and namespace in other branches
  1. 7.2 vendor/phpoffice/phpexcel/Classes/PHPExcel/Calculation/LookupRef.php \PHPExcel_Calculation_LookupRef::COLUMN()

* 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 function is being called through the calculation engine, then it is assumed to be the * reference of the cell in which the COLUMN function appears; otherwise this function returns 0. * * Excel Function: * =COLUMN([cellAddress]) * *

Parameters

cellAddress A reference to a range of cells for which you want the column numbers: * @return integer or array of integer

File

vendor/phpoffice/phpexcel/Classes/PHPExcel/Calculation/LookupRef.php, line 112

Class

PHPExcel_Calculation_LookupRef
PHPExcel_Calculation_LookupRef

Code

public static function COLUMN($cellAddress = Null) {
  if (is_null($cellAddress) || trim($cellAddress) === '') {
    return 0;
  }
  if (is_array($cellAddress)) {
    foreach ($cellAddress as $columnKey => $value) {
      $columnKey = preg_replace('/[^a-z]/i', '', $columnKey);
      return (int) PHPExcel_Cell::columnIndexFromString($columnKey);
    }
  }
  else {
    if (strpos($cellAddress, '!') !== false) {
      list($sheet, $cellAddress) = explode('!', $cellAddress);
    }
    if (strpos($cellAddress, ':') !== false) {
      list($startAddress, $endAddress) = explode(':', $cellAddress);
      $startAddress = preg_replace('/[^a-z]/i', '', $startAddress);
      $endAddress = preg_replace('/[^a-z]/i', '', $endAddress);
      $returnValue = array();
      do {
        $returnValue[] = (int) PHPExcel_Cell::columnIndexFromString($startAddress);
      } while ($startAddress++ != $endAddress);
      return $returnValue;
    }
    else {
      $cellAddress = preg_replace('/[^a-z]/i', '', $cellAddress);
      return (int) PHPExcel_Cell::columnIndexFromString($cellAddress);
    }
  }
}