header中怎么导出Excel应用,相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。
江西网站制作公司哪家好,找创新互联公司!从网页设计、网站建设、微信开发、APP开发、成都响应式网站建设公司等网站项目制作,到程序开发,运营维护。创新互联公司自2013年起到现在10年的时间,我们拥有了丰富的建站经验和运维经验,来保证我们的工作的顺利进行。专注于网站建设就选创新互联公司。where($where)->order($order)->select(); if(is_array($lists) && count($lists)>0) { if(empty($filename)) { $filename = date('Y-m-d',time()).'.csv'; } header('Content-type:application/vnd.ms-excel'); header('Content-Disposition:attachment;filename='.$filename); header('Pragma:no-cache'); header('Expires:0'); if($_POST['two_status']==0){ $csv= '分类,创意ID,创意类型,创意标签,创意标题,创意描述,评论数, 收藏数,投票数,提交人,作者'."\n"; }elseif($_POST['two_status']==1){ $csv= '分类,创意ID,创意类型,创意标签,创意标题,创意描述,评论数, 收藏数,投票数,提交人,作者,合作者,核心创新点说明,市场计划,已有类似商业化案例,相关专利状况,实现方式讨论,发表时间'."\n"; }else{ $csv= '分类,创意ID,创意类型,创意标签,创意标题,创意描述,评论数, 收藏数,投票数,提交人,作者,合作者,核心创新点说明,市场计划,已有类似商业化案例,相关专利状况,实现方式讨论,发表时间'."\n"; } foreach($lists as $list =>$v) { if($v['creative_type'] == 1){ $type = '问题'; }elseif($v['creative_type'] == 2){ $type = '解决方式'; }elseif($v['creative_type'] == 3){ $type = '新创意'; } if($v['two_status']==0) $fenlei="一句话创意"; if($v['two_status']==1) $fenlei="标准创意"; if($_POST['two_status']==0){ //一句话 $csv .= $fenlei1.','.$v['creative_id'].",".$v['sort_name'].','.$type.','.$v['creative_name'].','.$v['creative_description'].','.$v['comment_num'].','.$v['collect_num'].','.$v['vote_num'].','.$v['submitter'].','.$v['author']."\n"; }elseif($_POST['two_status']==1){ //标准 $csv .= $fenlei2.','.$v['creative_id'].",".$v['sort_name'].','.$type.','.$v['creative_name'].','.$v['creative_description'].','.$v['comment_num'].','.$v['collect_num'].','.$v['vote_num'].','.$v['submitter'].','.$v['author'].','.$v['collaborator'].','.$v['innovation_description'].','.$v['marketing_plan'].','.$v['business_case'].','.$v['patent_situation'].','.$v['discuss_ways'].','.strtotime($v['create_time'])."\n"; }else{ //全部 $csv .= $fenlei.','.$v['creative_id'].",".$v['sort_name'].','.$type.','.$v['creative_name'].','.$v['creative_description'].','.$v['comment_num'].','.$v['collect_num'].','.$v['vote_num'].','.$v['submitter'].','.$v['author'].','.$v['collaborator'].','.$v['innovation_description'].','.$v['marketing_plan'].','.$v['business_case'].','.$v['patent_situation'].','.$v['discuss_ways'].','.strtotime($v['create_time'])."\n"; } } echo mb_convert_encoding($csv,"CP936","UTF-8"); }else{ $this->assign("msg",$msg); } exit; } $this->display(); } public function votecount(){ if($_POST){ //@param $data array 需要导出的数据 //@param $field string 导出csv文件的列名 //@param $filename string 需要导出csv文件的名字 $where = '1'; if($_POST['crea_order'] == 1) $order = " c.vote_num desc"; $star = strtotime($_POST['control_star']); $end = strtotime($_POST['control_end']); if($star && $end) $where .= " and (c.vote_start_time between $star and $end) and (c.vote_end_time between $star and $end)"; $sql ="select c.sort_name,c.creative_id,c.creative_type,c.creative_name,c.creative_description,c.vote_num,c.comment_num,c.collect_num,c.create_time, u.username from cofco_creative as c left join cofco_userinfo as u on c.uid = u.uid where $where order by $order "; $lists = M()->query($sql); $csv = ''; if(is_array($lists) && count($lists)>0) { if(empty($filename)) { $filename = date('Y-m-d',time()).'.csv'; } header('Content-type:application/vnd.ms-excel'); header('Content-Disposition:attachment;filename='.$filename); header('Pragma:no-cache'); header('Expires:0'); $csv = '创意标签,提交者,创意分类,创意标题,创意简述,得票数,评论数, 收藏数,上传时间'."\n"; foreach($lists as $list =>$v) { if($v['creative_type'] == 1){ $type = '问题'; }elseif($v['creative_type'] == 2){ $type = '解决方式'; }elseif($v['creative_type'] == 3){ $type = '新创意'; } $time = date("Y-m-d H:i:s",$v['create_time']); $csv .= $v['sort_name'].','.$v['username'].','.$type.','.$v['creative_name'].','.$v['creative_description'].','.$v['vote_num'].','.$v['comment_num'].','.$v['collect_num'].','.$time."\n"; } echo mb_convert_encoding($csv,"CP936","UTF-8"); }else{ $this->assign("msg",$msg); } exit; } $this->display(); } } ?>
看完上述内容,你们掌握header中怎么导出Excel应用的方法了吗?如果还想学到更多技能或想了解更多相关内容,欢迎关注创新互联行业资讯频道,感谢各位的阅读!