下载PHPExcel:http://phpexcel.codeplex.com
- 解压压缩包里的Classes文件夹中的内容到application\libraries\目录下,目录结构如下:
-- application\libraries\PHPExcel.php
-- application\libraries\PHPExcel (文件夹)
2.修改application\libraries\PHPExcel\IOFactory.php 文件
-- 将其类名从PHPExcel_IOFactory改为IOFactory,遵从CI类命名规则。
-- 将其构造函数改为public
直接上代码吧
// 首先引入phpExcel类 放到library中
$this->load->library('PHPExcel');
$this->load->library('PHPExcel/IOFactory');
// 查询出项目下所有评过分的作品
$this->db->from('ps_works_judges');
$this->db->where('project_id',$project_id);
$this->db->where('is_total',1);
$data = $this->db->get()->result_array();
// 然后根据作品id查询评委给出的分数
$resultPHPExcel = new PHPExcel();
// 设置行数
$resultPHPExcel->getActiveSheet()->setCellValue('A1', '账号');
$resultPHPExcel->getActiveSheet()->setCellValue('B1', '姓名');
$resultPHPExcel->getActiveSheet()->setCellValue('C1', '手机');
$i = 2;
// 设置列数
foreach($data as $key){
$resultPHPExcel->getActiveSheet()->setCellValue('A' . $i, $key['account']);
$resultPHPExcel->getActiveSheet()->setCellValue('B' . $i, $key['name']);
$resultPHPExcel->getActiveSheet()->setCellValue('C' . $i, $key['tel']);
$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" );
网友评论