Home > php教程 > php手册 > body text

数字转字母,生成Excel列标

WBOY
Release: 2016-06-07 11:44:11
Original
1733 people have browsed it

在做Excel上传解析时,为了动态配置Excel与数据库表对应关系,由数组索引关联到Excel的某一列,需要将索引值转换为Excel列标,所以就写了这个方法,现在把代码帖出来,如果有更好的方法还请分享下,谢谢!
    /**<br>      * 数字转字母 (类似于Excel列标)<br>      * @param Int $index 索引值<br>      * @param Int $start 字母起始值<br>      * @return String 返回字母<br>      * @author Anyon Zou <anyon><br>      * @date 2013-08-15 20:18<br>      */<br>     function IntToChr($index, $start = 65) {<br>         $str = '';<br>         if (floor($index / 26) > 0) {<br>             $str .= IntToChr(floor($index / 26)-1);<br>         }<br>         return $str . chr($index % 26 + $start);<br>     }<br> <br>     /**<br>      * 测试<br>      */<br>     function test() {<br>         echo IntToChr(0); //# A<br>         echo IntToChr(1); //# B<br>         // ...<br>         echo IntToChr(27); //# AB<br>     }</anyon>

AD:真正免费,域名+虚机+企业邮箱=0元

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template