excel导出时列超过26时解决办法
/**
* 导出数据方法
* @author 杭州仟奇信息技术有限公司
*/
protected function getExcel($fileName,$headArr,$data){
//导入PHPExcel类库,因为PHPExcel没有用命名空间,只能inport导入
import("Org.Util.PHPExcel");
import("Org.Util.PHPExcel.Writer.Excel5");
import("Org.Util.PHPExcel.IOFactory.php");
$date = date("Y_m_d",time());
$fileName .= "_{$date}.xls";
//创建PHPExcel对象,注意,不能少了\
$objPHPExcel = new \PHPExcel();
$objProps = $objPHPExcel->getProperties();
//设置表头
$key = 0;
//print_r($headArr);exit;
foreach($headArr as $v){
//注意,不能少了。将列数字转换为字母\
$colum = \PHPExcel_Cell::stringFromColumnIndex($key);
$objPHPExcel->setActiveSheetIndex(0) ->setCellValue($colum.'1', $v);
$key += 1;
}
$column = 2;
$objActSheet = $objPHPExcel->getActiveSheet();
foreach($data as $key => $rows){ //行写入
$span = 0;
foreach($rows as $keyName=>$value){// 列写入
$j = \PHPExcel_Cell::stringFromColumnIndex($span);
$objActSheet->setCellValue($j.$column, $value);
$span++;
}
$column++;
}
$fileName = iconv("utf-8", "gb2312", $fileName);
//重命名表
$objPHPExcel->getActiveSheet()->setTitle($date);
//设置字体大小
$objPHPExcel->getDefaultStyle()->getFont()->setSize(14);
//设置单元格宽度
$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(15);
//设置默认行高
$objPHPExcel->getActiveSheet()->getDefaultRowDimension()->setRowHeight(23);
//设置活动单指数到第一个表,所以Excel打开这是第一个表
$objPHPExcel->setActiveSheetIndex(0);
header('Content-Type: application/vnd.ms-excel');
header("Content-Disposition: attachment;filename=\"$fileName\"");
header('Cache-Control: max-age=0');
$objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('php://output'); //文件通过浏览器下载
exit;
}