/**
* @Author: 小破孩嫩
* @Email: 3584685883@qq.com
* @Time: 2020/12/23 16:08
* @param int $column_num
* @return mixed
* @Description:获取表格列数的字母
*/
public function getMaxColumn(int $column_num)
{
try{
if(empty($column_num)){
throw new Exception('column_num:列数为空~');
}
if(!is_int($column_num)){
throw new Exception('column_num:参数类型错误~');
}
if($column_num > 26*26 || $column_num < 0){
throw new Exception('最大列数:676列,最小列数:1列');
}
$column_word = ['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'];
//生成循环次数
$num = ceil($column_num/26);
for($c = 0; $c < $num; $c++) {
$first_word = $column_word[$c-1];
foreach($column_word as $key => $val){
if($c >= 1){
$word = $first_word.$column_word[$key];
}else{
$word = $column_word[$key];
}
$column[] = $word;
}
}
for($a = 0; $a < $column_num; $a++){
$new_column[] = $column[$a];
}
return $new_column;
}catch (Exception $e){
returnResponse(100,$e->getMessage());
}
}
版权属于:
小破孩
作品采用:
《
署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0)
》许可协议授权
评论 (0)