php execl 列的长度,php生成excel列名超过26列大于Z时的解决方法
本文實例講述了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 < 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];? }將列的數字序號轉成字母使用,代碼如下:復制代碼 代碼如下:PHPExcel_Cell::stringFromColumnIndex($i); // 從o開始
將列的字母轉成數字序號使用,代碼如下:復制代碼 代碼如下:PHPExcel_Cell::columnIndexFromString("AA");
希望本文所述對大家的php程序設計有所幫助。
總結
以上是生活随笔為你收集整理的php execl 列的长度,php生成excel列名超过26列大于Z时的解决方法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: CPI是什么意思
- 下一篇: bicq php,BICQ v2.0.0