欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

php生成excel列名超過(guò)26列大于Z時(shí)的解決方法

 更新時(shí)間:2014年12月29日 09:43:27   投稿:shichen2014  
這篇文章主要介紹了php生成excel列名超過(guò)26列大于Z時(shí)的解決方法,是針對(duì)采用PHPExcel生成excel列數(shù)過(guò)多的情況下的完善技巧,具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

本文實(shí)例講述了php生成excel列名超過(guò)26列大于Z時(shí)的解決方法。分享給大家供大家參考。具體分析如下:

我們生成excel都會(huì)使用phpExcel類,這里就來(lái)給大家介紹在生成excel列名超過(guò)26列大于Z時(shí)的解決辦法,這是phpExcel類中的方法,今天查到了,記錄一下備忘,代碼如下:

復(fù)制代碼 代碼如下:
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 < 26) { 
                $_indexCache[$pColumnIndex] = chr(65 + $pColumnIndex); 
            } elseif ($pColumnIndex < 702) { 
                $_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]; 
}

將列的數(shù)字序號(hào)轉(zhuǎn)成字母使用,代碼如下:
復(fù)制代碼 代碼如下:
PHPExcel_Cell::stringFromColumnIndex($i); // 從o開始

將列的字母轉(zhuǎn)成數(shù)字序號(hào)使用,代碼如下:

復(fù)制代碼 代碼如下:
PHPExcel_Cell::columnIndexFromString('AA');

希望本文所述對(duì)大家的php程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論