Php generates an excel column name, with more than 26 columns greater than Z. solution. All the generated excel files use the phpExcel class. next I will introduce the solution to the problem that the generated excel column name contains more than 26 columns and is greater than Z. This is a method in the phpExcel class. Today we found that all the generated excel files use the phpExcel class. next I will introduce the solution to the problem of generating more than 26 columns of the excel column name than Z.
This is a method in the phpExcel class. I found it today and recorded my memo.
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 number of a column to a letter:
The code is as follows: |
|
PHPExcel_Cell: stringFromColumnIndex ($ I); // starts from o |
To convert a column's letters into numbers:
The code is as follows: |
|
PHPExcel_Cell: columnIndexFromString ('A '); |
Bytes. This is a method in the phpExcel class. Found today...