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