PHP生成EXCEL表头列名称

生成如下的数组:

A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z
AA,AB,AC,AD,AE,AF,AG,AH,AI,AJ,AK,AL,AM,AN,AO,AP,AQ,AR,AS,AT,AU,AV,AW,AX,AY,AZ
BA,BB,BC,BD,BE,BF,BG,BH,BI,BJ,BK,BL,BM,BN,BO,BP,BQ,BR,BS,BT,BU,BV,BW,BX,BY,BZ

 

用于导出EXCEL文件。

Select Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
function excel_header($num = 0)
{
    $arr = range('A', 'Z');

    $no = ceil($num / count($arr));

    $data = array();

    if ($no <= 1) {
        for ($i = 0; $i < $num; $i++) {
            $data[] = $arr[$i];
        }
    } else {
        for ($i = 0; $i < count($arr); $i++) {
            $data[] = $arr[$i];
        }
        for ($i = 0; $i < $num - count($arr); $i++) {
            $list = (($i + count($arr)) % count($arr));
            $data[] = $arr[ceil(($i + 1) / count($arr)) - 1] . $arr[$list];
        }
    }

    return $data;
}