Skip to content

Instantly share code, notes, and snippets.

@ToQoz
Created December 13, 2011 09:52
Show Gist options
  • Save ToQoz/1471448 to your computer and use it in GitHub Desktop.
Save ToQoz/1471448 to your computer and use it in GitHub Desktop.
数字からExcelの行番号?(AEとか)を得る
<?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