header exports the Excel application example
- 2020-12-21 18:00:05
- OfStack
<?php
class reportFormAction extends CommonAction{
public function index(){
if($_POST){
//@param $data array The data that needs to be exported
//@param $field string export csv The column name of the file
//@param $filename string Need to export the csv File name
$where = '1';
$order = 'creative_id desc';
if($_POST['crea_wh'] == 1) $order .= "";
if($_POST['crea_wh'] == 2) $order .= "creative_time desc";
$star = strtotime($_POST['control_star']);
$end = strtotime($_POST['control_end']);
if($star && $end) $where .= " and (create_time between $star and $end)";
if($_POST['creative_type'] == 1) $where .= " and creative_type =1";
if($_POST['creative_type'] == 2) $where .= " and creative_type =2";
if($_POST['creative_type'] == 3) $where .= " and creative_type =3";
if($_POST['sort_name'] == 1) $where .= " and sort_name = ' technical '";
if($_POST['sort_name'] == 2) $where .= " and sort_name = ' A wrapper class '";
if($_POST['sort_name'] == 3) $where .= " and sort_name = ' Product class '";
if($_POST['sort_name'] == 4) $where .= " and sort_name = ' The marketing class '";
if($_POST['sort_name'] == 5) $where .= " and sort_name = ' Other classes '";
if($_POST['two_status']==0) {$where .= " and two_status=0"; $fenlei1="1 Sentence creative ";}
if($_POST['two_status']==1) {$where .= " and two_status=1"; $fenlei2=" The standard of creative ";}
$csv = '';
$lists = M('creative')->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= ' classification , creative ID, Creative types , Creative label , Creative title , Creative description , comments , Collect the number , votes , Submit one , The author '."\n";
}elseif($_POST['two_status']==1){
$csv= ' classification , creative ID, Creative types , Creative label , Creative title , Creative description , comments , Collect the number , votes , Submit one , The author , collaborators , Description of core innovation points , Marketing plan , There have been similar cases of commercialization , Relevant Patent Status , Discussion on implementation Mode , Published time '."\n";
}else{
$csv= ' classification , creative ID, Creative types , Creative label , Creative title , Creative description , comments , Collect the number , votes , Submit one , The author , collaborators , Description of core innovation points , Marketing plan , There have been similar cases of commercialization , Relevant Patent Status , Discussion on implementation Mode , Published time '."\n";
}
foreach($lists as $list =>$v) {
if($v['creative_type'] == 1){
$type = ' The problem ';
}elseif($v['creative_type'] == 2){
$type = ' The solution ';
}elseif($v['creative_type'] == 3){
$type = ' New ideas ';
}
if($v['two_status']==0) $fenlei="1 Sentence creative ";
if($v['two_status']==1) $fenlei=" The standard of creative ";
if($_POST['two_status']==0){ //1 words
$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){ // standard
$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{ // all
$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 The data that needs to be exported
//@param $field string export csv The column name of the file
//@param $filename string Need to export the csv File name
$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 = ' Creative label , The submitter , Creative classification , Creative title , The creative brief , vote , comments , Collect the number , Upload time '."\n";
foreach($lists as $list =>$v) {
if($v['creative_type'] == 1){
$type = ' The problem ';
}elseif($v['creative_type'] == 2){
$type = ' The solution ';
}elseif($v['creative_type'] == 3){
$type = ' New ideas ';
}
$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();
}
}
?>