Home > Backend Development > PHP Tutorial > Solution when php generates excel column names with more than 26 columns and is larger than Z, excel26 columns_PHP tutorial

Solution when php generates excel column names with more than 26 columns and is larger than Z, excel26 columns_PHP tutorial

WBOY
Release: 2016-07-13 10:10:29
Original
940 people have browsed it

Solution when php generates excel column names with more than 26 columns and is larger than Z, excel26 columns

The example in this article describes the solution when php generates excel column names with more than 26 columns and is larger than Z. Share it with everyone for your reference. The specific analysis is as follows:

We all use the phpExcel class when generating excel. Here we will introduce to you the solution when generating excel column names that exceed 26 columns and are larger than Z. This is the method in the phpExcel class. I found it today. Record the memo and code. As follows:

Copy code The code is as follows:
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];
}

Convert the numeric serial number of the column into letters. The code is as follows:


Copy code The code is as follows:PHPExcel_Cell::stringFromColumnIndex($i); // Start with o
Convert the letters of the column into numerical serial numbers. The code is as follows:


Copy code The code is as follows:PHPExcel_Cell::columnIndexFromString('AA');
I hope this article will be helpful to everyone’s PHP programming design.

http://www.bkjia.com/PHPjc/934932.html

truehttp: //www.bkjia.com/PHPjc/934932.htmlTechArticleSolution when php generates excel column names with more than 26 columns and is larger than Z, excel26 columns This article tells the example of php generating excel Solution when the column name exceeds 26 and the column is larger than Z. Share it with everyone for your reference. ...
Related labels:
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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template