您好,欢迎访问一九零五行业门户网

php生成excel列名超过26列大于Z时的解决方法_PHP

本文实例讲述了php生成excel列名超过26列大于z时的解决方法。分享给大家供大家参考。具体分析如下:
我们生成excel都会使用phpexcel类,这里就来给大家介绍在生成excel列名超过26列大于z时的解决办法,这是phpexcel类中的方法,今天查到了,记录一下备忘,代码如下:
代码如下:
public static function stringfromcolumnindex($pcolumnindex = 0) 

        //  using a lookup cache adds a slight memory overhead, but boosts speed 
        //  caching using a static within the method is faster than a class static, 
        //      though it's additional memory overhead 
        static $_indexcache = array();
if (!isset($_indexcache[$pcolumnindex])) { 
            // determine column string 
            if ($pcolumnindex                 $_indexcache[$pcolumnindex] = chr(65 + $pcolumnindex); 
            } elseif ($pcolumnindex                 $_indexcache[$pcolumnindex] = chr(64 + ($pcolumnindex / 26)) . chr(65 + $pcolumnindex % 26); 
            } else {
                $_indexcache[$pcolumnindex] = chr(64 + (($pcolumnindex - 26) / 676)) . chr(65 + ((($pcolumnindex - 26) % 676) / 26)) . chr(65 + $pcolumnindex % 26); 
            } 
        } 
        return $_indexcache[$pcolumnindex]; 
}
将列的数字序号转成字母使用,代码如下:
代码如下:
phpexcel_cell::stringfromcolumnindex($i); // 从o开始
将列的字母转成数字序号使用,代码如下:
代码如下:
phpexcel_cell::columnindexfromstring('aa');
希望本文所述对大家的php程序设计有所帮助。
其它类似信息

推荐信息