Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
100.00% |
1 / 1 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
13 / 13 |
| XlsxUtil | |
100.00% |
1 / 1 |
|
100.00% |
2 / 2 |
8 | |
100.00% |
13 / 13 |
| xlsx_sheetName_sanitize | |
100.00% |
1 / 1 |
3 | |
100.00% |
6 / 6 |
|||
| xlsx_colNum2colLetter | |
100.00% |
1 / 1 |
5 | |
100.00% |
7 / 7 |
|||
| <?php | |
| namespace ia\Util; | |
| class XlsxUtil { | |
| /** | |
| * Sanitize $sheet_name to be used as excel's tab name | |
| * | |
| * @param string $sheet_name | |
| * @return string sanitized $sheet_name to be used as tab name | |
| */ | |
| public static function xlsx_sheetName_sanitize($sheet_name) { | |
| $sheet_name = str_replace(array("\\", '/', '?', '*', ':', '[', ']'), '_', Str::strim($sheet_name)); | |
| if(substr($sheet_name, 0, 1) === "'") { | |
| $sheet_name = substr($sheet_name,1); | |
| } | |
| if(substr($sheet_name, -1) === "'") { | |
| $sheet_name = substr($sheet_name, 0, -1); | |
| } | |
| return substr($sheet_name, 0, 32); | |
| } | |
| /** | |
| * Returns excel's column letter(s) for $colNum | |
| * | |
| * @param int $colNum Current column number, zero based 0=A, in case errors are reported | |
| * @return string Excel's column letter(s), '' (blank) on error | |
| */ | |
| public static function xlsx_colNum2colLetter($colNum) { | |
| if(!is_numeric($colNum) || $colNum < 0) | |
| return ''; | |
| if($colNum < 26) { | |
| return chr($colNum + 65); | |
| } | |
| if($colNum < 702) { | |
| return chr(64 + ($colNum / 26)) . chr(65 + $colNum % 26); | |
| } | |
| return chr(64 + (($colNum - 26) / 676)) . chr(65 + ((($colNum - 26) % 676) / 26)) . chr(65 + $colNum % 26); | |
| } | |
| } | |