/** * @名称:获取字母 * @param $index * User: congxion * Date: */ function getColumnIndex($index) { if ($index >= 0 && $index < 26) { // 如果是 A 到 Z 之间的列,直接返回对应的字母 return chr(65 + $index); } else { // 针对 AA、AB、AC ... ZZ 这样的列,使用类似递归的方式计算出对应的字母组合 $result = ''; while ($index >= 26) { $result .= chr(65 + ($index % 26)); $index = intval($index / 26) - 1; } $result .= chr(65 + $index); return strrev($result); // 需要反转列名字母组合 } }