php A-ZZ phpExcel获取列
2022-03-24 PHP 1843
<?php function getColKeys($colkey) { $colkeys = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']; $cols = []; $len = strlen($colkey); for ($i = 0; $i < $len; $i++) { $cols[$i] = $colkey[$i]; } $keys = $colkeys; foreach ($colkeys as $value) { foreach ($colkeys as $v) { $key = $value . $v; $keys[] = $key; if ($key == $colkey) { return $keys; } } } return $keys; } function getColKeys(string $colkey): array { $colkeys = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']; $cols = []; $len = strlen($colkey); for ($i = 0; $i < $len; $i++) { $cols[$i] = $colkey[$i]; } $keys = $colkeys; foreach ($colkeys as $value) { foreach ($colkeys as $v) { $key = $value . $v; $keys[] = $key; if ($key == $colkey) { return $keys; } } } return $keys; } $colkey = 'BG'; print_r(getColKeys($colkey));
很赞哦! (0)
相关文章
文章评论
-
-
-
0条评论