Skip to content

Instantly share code, notes, and snippets.

@marcogrueter
Created September 19, 2013 14:45
Show Gist options
  • Save marcogrueter/6624600 to your computer and use it in GitHub Desktop.
Save marcogrueter/6624600 to your computer and use it in GitHub Desktop.
get the correct excel style column name
// $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