解壓壓縮包裏的Classes文件夾中的內容到application\libraries\目錄下,目錄結構以下:
--application\libraries\PHPExcel.php
--application\libraries\PHPExcel(文件夾)
修改application\libraries\PHPExcel\IOFactory.php文件
--將其類名從PHPExcel_IOFactory改成IOFactory,聽從CI類命名規則。
--將其構造函數改成publicphp
$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" );