/** * 导出excel 格式为csv 自己改 */public function export(){ ##设置表头 header("Content-type:text/csv"); header("Content-Disposition:attachment;filename=".date('YmdHis',time()).".csv"); header('Cache-Control:must-revalidate,post-check=0,pre-check=0'); header('Expires:0'); header('Pragma:public'); ##标题栏 $title = array( '序号', '用户', '部门', '管理员', '类型', '个人成绩', '达标成绩', '系数', '年', '月', '时间' ); $title = implode(',',$title); ##输出标题 echo iconv('utf-8','gbk', $title."\r\n"); ##查询条件 $option=array('year'=>$year); ##导出记录 $this->_echoLogData($option, 1);}
/** * 循环递归输出记录 */public function _echoLogData($option, $page){ static $index = 1; $firstNumber = ($page - 1) * 1000;//限制一次查询1000条, $data = M('user_assessment_log')->alias('ual') ->field('u.nickname,se.sec_name,u.is_admin,ual.asse_type,ual.assessment_result, ual.standard_score,ual.coefficient,ual.year,ual.month,ual.create_time') ->join('user u on u.user_id = ual.user_id') ->join('bang_section se on se.section_id = u.section_id') ->where($option) ->limit($firstNumber, 1000) ->order('ual.asse_id desc') ->select(); ##如果数据存在,则将数据一条一条输出 if($data){ foreach ($data as $v){ $str = $index; foreach ($v as $vv){ $str .= (','."\"$vv\""); } echo iconv('utf-8','gbk', $str."\r\n"); $index ++; } $page ++; $this->_echoLogData($option, $page);//递归再一次查询 } }