Created
December 13, 2011 09:52
-
-
Save ToQoz/1471448 to your computer and use it in GitHub Desktop.
数字からExcelの行番号?(AEとか)を得る
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 getAlphabetByNum($num, $carryNum=null) { | |
$alphabetCount = 26; | |
if ($num < $alphabetCount) { | |
if ($carryNum === null) return chr(97 + $num); | |
$carryAlphabet = ($carryNum > $alphabetCount) ? getAlphabetByNum($carryNum) : | |
chr(97 + $carryNum); | |
return $carryAlphabet . chr(97 + $num); | |
} | |
$carryNum = ($carryNum === null) ? 0 : $carryNum + 1; | |
return getAlphabetByNum($num - $alphabetCount, $carryNum); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment