如何根据输入数量自动生成对应Excel列标的数组列表?
- 内容介绍
- 相关推荐
本文共计267个文字,预计阅读时间需要2分钟。
Excel.php 脚本示例:
php 1000) { echo 示例:http://localhost/excel.php?num=100;} elseif ($num==702) { echo 暂时最大支持到702;} else { $arr=get_field($num); echo ; print_r($arr);}
function get_field($num) { // $num=I('param.num'); $index='ce';}?>
'; echo '示例: localhost/excel.php?num=100'; }elseif($num > 702){ echo '暂时最大只支持到702'; }else{ $arr = get_field($num); echo '
'; print_r($arr); } function get_field($num) { //$num = I('param.num'); $index = ceil(($num - 26) / 26); $a = []; for ($i = 1; $i <= $index; $i++) { $arr = get_excel_field(26 * $i); $a = array_merge($a, $arr); } $final = get_excel_field($num); $a = array_merge($a, $final); return $a; } //根据字段的数量,生成符合EXCEL规则的列号 function get_excel_field($num) { if (empty($num)) { return false; } $index = intval($num / 26); //整数部分 $offset = $num % 26; //余数部分 //获取基础字母表 for ($i = 65; $i < 91; $i++) { $ab[] = strtoupper(chr($i)); } if ($num == 26) return $ab; $start = 65; if ($index < 1) { $end = $start + $offset; for ($i = $start; $i < $end; $i++) { $arr[] = strtoupper(chr($i)); } } else { if ($offset == 0) { $offset = 26; $index = $index - 1; } $a = get_excel_field($offset); $c = get_excel_field($index); for ($t = $index - 1; $t < $index; $t++) { for ($i = 0; $i < $offset; $i++) { $arr[] = $c[$t] . $a[$i]; } } } return $arr; } ?>
本文共计267个文字,预计阅读时间需要2分钟。
Excel.php 脚本示例:
php 1000) { echo 示例:http://localhost/excel.php?num=100;} elseif ($num==702) { echo 暂时最大支持到702;} else { $arr=get_field($num); echo ; print_r($arr);}
function get_field($num) { // $num=I('param.num'); $index='ce';}?>
'; echo '示例: localhost/excel.php?num=100'; }elseif($num > 702){ echo '暂时最大只支持到702'; }else{ $arr = get_field($num); echo '
'; print_r($arr); } function get_field($num) { //$num = I('param.num'); $index = ceil(($num - 26) / 26); $a = []; for ($i = 1; $i <= $index; $i++) { $arr = get_excel_field(26 * $i); $a = array_merge($a, $arr); } $final = get_excel_field($num); $a = array_merge($a, $final); return $a; } //根据字段的数量,生成符合EXCEL规则的列号 function get_excel_field($num) { if (empty($num)) { return false; } $index = intval($num / 26); //整数部分 $offset = $num % 26; //余数部分 //获取基础字母表 for ($i = 65; $i < 91; $i++) { $ab[] = strtoupper(chr($i)); } if ($num == 26) return $ab; $start = 65; if ($index < 1) { $end = $start + $offset; for ($i = $start; $i < $end; $i++) { $arr[] = strtoupper(chr($i)); } } else { if ($offset == 0) { $offset = 26; $index = $index - 1; } $a = get_excel_field($offset); $c = get_excel_field($index); for ($t = $index - 1; $t < $index; $t++) { for ($i = 0; $i < $offset; $i++) { $arr[] = $c[$t] . $a[$i]; } } } return $arr; } ?>

