《PHP實(shí)例:php生成excel列名超過(guò)26列大于Z時(shí)的解決方法》要點(diǎn):
本文介紹了PHP實(shí)例:php生成excel列名超過(guò)26列大于Z時(shí)的解決方法,希望對(duì)您有用。如果有疑問(wèn),可以聯(lián)系我們。
PHP編程本文實(shí)例講述了php生成excel列名超過(guò)26列大于Z時(shí)的解決辦法.分享給大家供大家參考.具體分析如下:
PHP編程我們生成excel都會(huì)使用phpExcel類,這里就來(lái)給大家介紹在生成excel列名超過(guò)26列大于Z時(shí)的解決方法,這是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 < 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)成字母使用,代碼如下:
代碼如下:
PHPExcel_Cell::stringFromColumnIndex($i); // 從o開始
PHP編程將列的字母轉(zhuǎn)成數(shù)字序號(hào)使用,代碼如下:
代碼如下:
PHPExcel_Cell::columnIndexFromString('AA');
PHP編程希望本文所述對(duì)大家的php程序設(shè)計(jì)有所贊助.
維易PHP培訓(xùn)學(xué)院每天發(fā)布《PHP實(shí)例:php生成excel列名超過(guò)26列大于Z時(shí)的解決方法》等實(shí)戰(zhàn)技能,PHP、MYSQL、LINUX、APP、JS,CSS全面培養(yǎng)人才。
轉(zhuǎn)載請(qǐng)注明本頁(yè)網(wǎng)址:
http://www.snjht.com/jiaocheng/13153.html