Home > php教程 > php手册 > excel导出时列超过26时解决办法

excel导出时列超过26时解决办法

WBOY
Release: 2016-06-07 11:38:41
Original
1468 people have browsed it

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元

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template