0 * Z => 25 * AA => 26 : (26^(2-1) * (0+1)) + 0 * AB => 27 : (26^(2-1) * (0+1)) + 1 * BC => 54 : (26^(2-1) * (1+1)) + 2 * BCZ => 1455 : (26^(3-1) * (1+1)) + (26^(2-1) * (2+1)) + 25 */ foreach (str_split($column) as $single_cell_index) { $currentColumnIndex = ord($single_cell_index) - $capitalAAsciiValue; if ($columnLength == 1) { $columnIndex += $currentColumnIndex; } else { $columnIndex += pow($step, ($columnLength - 1)) * ($currentColumnIndex + 1); } $columnLength--; } return $columnIndex; } /** * Returns whether a cell index is valid, in an Excel world. * To be valid, the cell index should start with capital letters and be followed by numbers. * * @param string $cellIndex The Excel cell index ('A1', 'BC13', ...) * @return bool */ protected static function isValidCellIndex($cellIndex) { return (preg_match('/^[A-Z]+\d+$/', $cellIndex) === 1); } }