Last active
May 13, 2021 07:51
-
-
Save Digi92/23432a987fba0422578cbcdcaad97b73 to your computer and use it in GitHub Desktop.
This function will convert a number to an excel-like column name.
For example:
1 => A
2 => B
27 => AA
28 => AB
14558 => UMX URL: https://stackoverflow.com/questions/3302857/algorithm-to-get-the-excel-like-column-name-of-a-number#answer-3302991
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
<?php | |
function getNameFromNumber($num) { | |
$numeric = $num % 26; | |
$letter = chr(65 + $numeric); | |
$num2 = intval($num / 26); | |
if ($num2 > 0) { | |
return $this->getNameFromNumber($num2 - 1) . $letter; | |
} else { | |
return $letter; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment