CodeIgniterCodeigniter+PHPExcel导出数据到Excel文件
解压压缩包里的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" );
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。