Monday, January 30, 2017
PHP function that return char of column on excel by number
Function that return column char of excel using on PHP programming. Call the function with the number that you want to fund the Char of column
//this function return the char of column from number
function column_char_from_nr($num) {
$numeric = ($num - 1) % 26;
$letter = chr(65 + $numeric);
$num2 = intval(($num - 1) / 26);
if ($num2 > 0) {
return getNameFromNumber($num2) . $letter;
} else {
return $letter;
}
}
For example:
$nr = 5;
$char= column_char_from_nr($nr);
echo "The char of column in excel for number = ".$nr." is <b>".$char."</b>";
// return E
//A B C D E F G ......
//1 2 3 4 5 6 7 ......
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment