Jquery中文网 www.jquerycn.cn
Jquery中文网 >  脚本编程  >  php  >  正文 php的phpExcel类生成excel时列超过26大于Z时如何解决

php的phpExcel类生成excel时列超过26大于Z时如何解决

发布时间:2018-09-05   编辑:www.jquerycn.cn
jquery中文网为您提供php的phpExcel类生成excel时列超过26大于Z时如何解决等资源,欢迎您收藏本站,我们将为您提供最新的php的phpExcel类生成excel时列超过26大于Z时如何解决资源
本文我们来分享用php的phpExcel类生成的excel当列名超过26列大于Z时的解决方法,供大家参考学习。

我们生成excel都会使用phpExcel类,这里就来给大家介绍在生成excel列名超过26列大于Z时的解决办法,这是phpExcel类中的方法,今天查到了,记录一下备忘,代码如下:

<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy4165')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy4165>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];
}</td></tr></table>


将列的数字序号转成字母使用,代码如下:

<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy7313')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy7313>PHPExcel_Cell::stringFromColumnIndex($i); // 从o开始</td></tr></table>

将列的字母转成数字序号使用,代码如下:

<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy4550')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy4550>PHPExcel_Cell::columnIndexFromString('AA');</td></tr></table>

希望本文所述对大家的php程序设计有所帮助。

您可能感兴趣的文章:
php的phpExcel类生成excel时列超过26大于Z时如何解决
PHP导入与导出Excel文件的方法
解决php下载excel无法打开的问题
phpexcel导入excel到数据库的代码
PHPExcel导出时列过大问题解决办法
PHPExcel实例代码 phpexcel类库示例
PHPExcel导出Excel文件时出现错误的解决办法
PHP通过PHPExcel类导入导出excel
drupal读取excel并导入数据库方法
phpexcel快速开发指南(不错)

[关闭]