Header Export Excel application example

Source: Internet
Author: User
Tags foreach exit comments count

  This article introduces you to use header to export Excel, the specific implementation code as follows, interested friends do not miss

The code is as follows: <?php  class Reportformaction extends commonaction{    Public Function index () {  if ($_post) { //@param $data array needs to export data  //@param $field string export CSV file column name  //@param $filename string needs to export the name of the CSV file & nbsp $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[' con Trol_end '];  if ($star && $end) $where. = "and (Create_time between $star and $end)";  if ($_post[' creat Ive_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 class '";  if ($_post[' sort_name '] = = 2) $where. = "and Sort_name = ' wrapper class '";  if ($_post[' Sort_na Me '] = = 3) $where.= "and Sort_name = ' Product class '";  if ($_post[' sort_name '] = = 4) $where. = "and Sort_name = ' marketing class '";  if ($_post[' Sort_n Ame '] = = 5 $where. = "and Sort_name = ' other class '";  if ($_post[' Two_status ']==0) {$where. = "and two_status=0"; $fenlei 1 = "A word of originality";}   if ($_post[' Two_status ']==1) {$where. = "and Two_status=1"; $fenlei 2 = "Standard 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 type, creative label, creative title, creative description, comments, favorites, votes, author, author '. ' N "; }elseif ($_post[' two_status ']==1) {  $csv = ' category, creative ID, creative type, creative label, creative title, creative description, comments, favorites, votes, author, author, partner, Core innovation Point Description, market plan, already have similar businessBusiness case, related patent status, realization mode discussion, publication time '. ' N "; }else{  $csv = ' classification, creative ID, creative type, creative label, creative title, creative description, comments, favorites, votes, author, author, partner, core Innovation Point description, marketing plan, similar commercial case, related patent status, Implementation discussion, publication time '. ' N "; }  foreach ($lists as $list => $v) {  if ($v [' creative_type '] = 1) {  $type = ' problem '; }elseif ($v [' creative_type '] = = 2) {  $type = ' Resolution '; }elseif ($v [' creative_type '] = = 3) {  $type = ' new creative '; }  if ($v [' Two_status ']== 0 $fenlei = "One word creative";  if ($v [' Two_status ']==1) $fenlei = "Standard creative";  if ($_post[' Two_status ']==0) {//Word   $ CSV. = $fenlei 1. ', '. $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. = $fenlei 2 ', '. $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 (); }    &nbs P Public Function Votecount () {  if ($_post) { //@param $data array needs to export the data &nbSp @param $field string to export the column name of the CSV file  //@param $filename string needs to export the name of the CSV file   $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_en D _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)) {  $fi Lename = 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, submitter, creative category, creative title, Creative brief, number of votes, comments, favorites, upload time '. ' N ";  foreach ($lists as $list => $v) {  if ($v [' creative_type '] = 1) {  $type = ' problem '; }elseif ($v [' CRE Ative_type '] = = 2 {  $type = ' Resolution '; }elseif ($v [' creative_type '] = = 3) {  $type = ' new creative '; }  $tim E = 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 (); } } ?> 
Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.