PHPExcel生成多列多行程序
//输出表头 $length = count($data_topic); $begin = ord('A'); $end = $begin + $length; $middle = ord('Z'); for($i = $begin; $i <= $end; $i++){ if($i < $middle){ $letter = chr($i); }else{ $letter = 'A' . chr($i - 26); } $objWorksheet->setCellValue($letter.'2', $data_topic[$i - 65]); } //excel 数据区 $i = $begin; $n = 0; foreach($data as $k2 => $v2){ $line = 3 + $n; foreach($v2 as $k3 => $v3){ if($i < $middle){ $letter = chr($i); }else{ $letter = 'A' . chr($i - 26); } $objWorksheet->setCellValue($letter.$line, $v3); $i += 1; } $n = $n + 1; }
此段程序支持A-AZ共52列。
A1用于标题,所以表头从A2开始,A3为数据体开始。