• Codeigniter+PHPExcel导出数据到Excel文件


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

     1 $this->load->library('PHPExcel');
     2         $this->load->library('PHPExcel/IOFactory');
     3         $resultPHPExcel = new PHPExcel();
     4         $resultPHPExcel->getActiveSheet()->setCellValue('A1', '项目'); 
     5         $resultPHPExcel->getActiveSheet()->setCellValue('B1', '结果'); 
     6         $resultPHPExcel->getActiveSheet()->setCellValue('C1', '数量'); 
     7         $i = 2; 
     8         foreach($m_data['jc_fia'] as $key){ 
     9             $resultPHPExcel->getActiveSheet()->setCellValue('A' . $i, $key[0]); 
    10             $resultPHPExcel->getActiveSheet()->setCellValue('B' . $i, $key[1]); 
    11             $resultPHPExcel->getActiveSheet()->setCellValue('C' . $i, $key[0]); 
    12             $i ++; 
    13         }
    14         $outputFileName = "123.xls";
    15         $xlsWriter = new PHPExcel_Writer_Excel5($resultPHPExcel); 
    16         header("Content-Type: application/force-download"); 
    17         header("Content-Type: application/octet-stream"); 
    18         header("Content-Type: application/download"); 
    19         header('Content-Disposition:inline;filename="'.$outputFileName.'"'); 
    20         header("Content-Transfer-Encoding: binary"); 
    21         header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); 
    22         header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); 
    23         header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); 
    24         header("Pragma: no-cache"); 
    25         $xlsWriter->save( "php://output" );
  • 相关阅读:
    清除缓存
    框架更新 (简)
    Xutils简
    动画
    夜间模式
    TabLoaout简单框架
    atomic原子类的理解
    单例模式中指令重排序及需要使用volatile的理解
    对volatile的理解
    jvm内存模型及垃圾回收GC
  • 原文地址:https://www.cnblogs.com/ygcool/p/5395317.html
Copyright © 2020-2023  润新知