Created
September 19, 2013 14:45
-
-
Save marcogrueter/6624600 to your computer and use it in GitHub Desktop.
get the correct excel style column name
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// $c=1 -> A | |
// $c=27 -> AA | |
// combine with the row index to get the correct cell identifier, | |
// e.g. | |
// $column = _excel_column(26); | |
// $cell = $columns . '3'; // = Z3 | |
public function _excel_column($c) | |
{ | |
$c = intval($c); | |
if ($c <= 0) return ''; | |
$letter = ''; | |
while($c != 0){ | |
$p = ($c - 1) % 26; | |
$c = intval(($c - $p) / 26); | |
$letter = chr(65 + $p) . $letter; | |
} | |
return $letter; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment