首页 > Web开发 > 详细

CodeIgniterCodeigniter+PHPExcel导出数据到Excel文件

时间:2014-08-13 21:50:17      阅读:363      评论:0      收藏:0      [点我收藏+]

解压压缩包里的Classes文件夹中的内容到application\libraries\目录下,目录结构如下:
--application\libraries\PHPExcel.php
--application\libraries\PHPExcel(文件夹)
修改application\libraries\PHPExcel\IOFactory.php文件
--将其类名从PHPExcel_IOFactory改为IOFactory,遵从CI类命名规则。
--将其构造函数改为public

        $this->load->library(PHPExcel);
        $this->load->library(PHPExcel/IOFactory);
        $resultPHPExcel = new PHPExcel();
        $resultPHPExcel->getActiveSheet()->setCellValue(A1, 项目); 
        $resultPHPExcel->getActiveSheet()->setCellValue(B1, 结果); 
        $resultPHPExcel->getActiveSheet()->setCellValue(C1, 数量); 
        $i = 2; 
        foreach($m_data[jc_fia] as $key){ 
            $resultPHPExcel->getActiveSheet()->setCellValue(A . $i, $key[0]); 
            $resultPHPExcel->getActiveSheet()->setCellValue(B . $i, $key[1]); 
            $resultPHPExcel->getActiveSheet()->setCellValue(C . $i, $key[0]); 
            $i ++; 
        }
        $outputFileName = "123.xls";
        $xlsWriter = new PHPExcel_Writer_Excel5($resultPHPExcel); 
        header("Content-Type: application/force-download"); 
        header("Content-Type: application/octet-stream"); 
        header("Content-Type: application/download"); 
        header(Content-Disposition:inline;filename=".$outputFileName."); 
        header("Content-Transfer-Encoding: binary"); 
        header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); 
        header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); 
        header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); 
        header("Pragma: no-cache"); 
        $xlsWriter->save( "php://output" );

 

CodeIgniterCodeigniter+PHPExcel导出数据到Excel文件,布布扣,bubuko.com

CodeIgniterCodeigniter+PHPExcel导出数据到Excel文件

原文:http://www.cnblogs.com/whlives/p/3910781.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!