php生成excel列名超過26列大于Z時的解決方法
本文實例講述了php生成excel列名超過26列大于Z時的解決方法。分享給大家供大家參考。具體分析如下:
我們生成excel都會使用phpExcel類,這里就來給大家介紹在生成excel列名超過26列大于Z時的解決辦法,這是phpExcel類中的方法,今天查到了,記錄一下備忘,代碼如下:
{
// 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ù)字序號轉(zhuǎn)成字母使用,代碼如下:
將列的字母轉(zhuǎn)成數(shù)字序號使用,代碼如下:
希望本文所述對大家的php程序設(shè)計有所幫助。
相關(guān)文章
php統(tǒng)計數(shù)組不同元素的個數(shù)的實例方法
在本篇文章里小編給大家整理的是關(guān)于php統(tǒng)計數(shù)組不同元素的個數(shù)的實例方法以及相關(guān)知識點,有需要的朋友們學(xué)習(xí)下。2019-09-09PHP實現(xiàn)的redis主從數(shù)據(jù)庫狀態(tài)檢測功能示例
這篇文章主要介紹了PHP實現(xiàn)的redis主從數(shù)據(jù)庫狀態(tài)檢測功能,涉及php針對多個redis主從數(shù)據(jù)庫的連接、檢測、錯誤信息輸出及郵件發(fā)送相關(guān)操作技巧,需要的朋友可以參考下2017-07-07PHP將整個網(wǎng)站生成HTML純靜態(tài)網(wǎng)頁的方法總結(jié)
我經(jīng)常會在網(wǎng)上看到有人問怎么將整個動態(tài)的網(wǎng)站靜態(tài)化,其實實現(xiàn)的方法很簡單2012-02-02