We generate Excel will use the Phpexcel class, let me introduce you in the generation of Excel column name more than 26 columns greater than Z problem resolution.
This is the method in the Phpexcel class. I found it today, record the memo.
The code is as follows |
Copy Code |
Pub Lic static function stringfromcolumnindex ($pColumnIndex = 0) { //Using a lookup cache adds a slight memory over Head, 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 <) { $_indexcache[$pColumnIndex] = chr (+ $pColumnIndex); } elseif ($pColumnIndex < 702) { $_indexcache[$pColumnIndex] = Chr (+ ($pColumnIndex/26)). Chr (+ $pColumnIndex% 26); } else { $_indexcache[$pColumnIndex] = Chr (($pColumnIndex-26)/676). Chr ((($pColumnIndex-26)% 676)/26). Chr (+ $pColumnIndex% 26); } } return $_indexcache[$pColumnIndex]; } |
To convert a column's numeric number to a letter, use:
The code is as follows |
Copy Code |
Phpexcel_cell::stringfromcolumnindex ($i); Start from O |
To convert the letter of a column to a numeric ordinal using:
The code is as follows |
Copy Code |
Phpexcel_cell::columnindexfromstring (' AA '); |
http://www.bkjia.com/PHPjc/632927.html www.bkjia.com true http://www.bkjia.com/PHPjc/632927.html techarticle we generate Excel will use the Phpexcel class, let me introduce you in the generation of Excel column name more than 26 columns greater than Z problem resolution. This is the method in the Phpexcel class. Today I found out ...