header導(dǎo)出Excel應(yīng)用示例
更新時(shí)間:2014年01月24日 16:07:37 作者:
本文為大家介紹下使用header導(dǎo)出Excel,具體實(shí)現(xiàn)代碼如下,感興趣的朋友不要錯(cuò)過(guò)
復(fù)制代碼 代碼如下:
<?php
class reportFormAction extends CommonAction{
public function index(){
if($_POST){
//@param $data array 需要導(dǎo)出的數(shù)據(jù)
//@param $field string 導(dǎo)出csv文件的列名
//@param $filename string 需要導(dǎo)出csv文件的名字
$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 = '技術(shù)類'";
if($_POST['sort_name'] == 2) $where .= " and sort_name = '包裝類'";
if($_POST['sort_name'] == 3) $where .= " and sort_name = '產(chǎn)品類'";
if($_POST['sort_name'] == 4) $where .= " and sort_name = '營(yíng)銷類'";
if($_POST['sort_name'] == 5) $where .= " and sort_name = '其他類'";
if($_POST['two_status']==0) {$where .= " and two_status=0"; $fenlei1="一句話創(chuàng)意";}
if($_POST['two_status']==1) {$where .= " and two_status=1"; $fenlei2="標(biāo)準(zhǔn)創(chuàng)意";}
$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= '分類,創(chuàng)意ID,創(chuàng)意類型,創(chuàng)意標(biāo)簽,創(chuàng)意標(biāo)題,創(chuàng)意描述,評(píng)論數(shù), 收藏?cái)?shù),投票數(shù),提交人,作者'."\n";
}elseif($_POST['two_status']==1){
$csv= '分類,創(chuàng)意ID,創(chuàng)意類型,創(chuàng)意標(biāo)簽,創(chuàng)意標(biāo)題,創(chuàng)意描述,評(píng)論數(shù), 收藏?cái)?shù),投票數(shù),提交人,作者,合作者,核心創(chuàng)新點(diǎn)說(shuō)明,市場(chǎng)計(jì)劃,已有類似商業(yè)化案例,相關(guān)專利狀況,實(shí)現(xiàn)方式討論,發(fā)表時(shí)間'."\n";
}else{
$csv= '分類,創(chuàng)意ID,創(chuàng)意類型,創(chuàng)意標(biāo)簽,創(chuàng)意標(biāo)題,創(chuàng)意描述,評(píng)論數(shù), 收藏?cái)?shù),投票數(shù),提交人,作者,合作者,核心創(chuàng)新點(diǎn)說(shuō)明,市場(chǎng)計(jì)劃,已有類似商業(yè)化案例,相關(guān)專利狀況,實(shí)現(xiàn)方式討論,發(fā)表時(shí)間'."\n";
}
foreach($lists as $list =>$v) {
if($v['creative_type'] == 1){
$type = '問(wèn)題';
}elseif($v['creative_type'] == 2){
$type = '解決方式';
}elseif($v['creative_type'] == 3){
$type = '新創(chuàng)意';
}
if($v['two_status']==0) $fenlei="一句話創(chuàng)意";
if($v['two_status']==1) $fenlei="標(biāo)準(zhǔn)創(chuàng)意";
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){ //標(biāo)準(zhǔn)
$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 需要導(dǎo)出的數(shù)據(jù)
//@param $field string 導(dǎo)出csv文件的列名
//@param $filename string 需要導(dǎo)出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 = '創(chuàng)意標(biāo)簽,提交者,創(chuàng)意分類,創(chuàng)意標(biāo)題,創(chuàng)意簡(jiǎn)述,得票數(shù),評(píng)論數(shù), 收藏?cái)?shù),上傳時(shí)間'."\n";
foreach($lists as $list =>$v) {
if($v['creative_type'] == 1){
$type = '問(wèn)題';
}elseif($v['creative_type'] == 2){
$type = '解決方式';
}elseif($v['creative_type'] == 3){
$type = '新創(chuàng)意';
}
$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();
}
}
?>
相關(guān)文章
解析linux下安裝memcacheq(mcq)全過(guò)程筆記
本篇文章是對(duì)linux下安裝memcacheq(mcq)全過(guò)程筆記進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-06-06php實(shí)現(xiàn)監(jiān)控varnish緩存服務(wù)器的狀態(tài)
這篇文章主要介紹了php實(shí)現(xiàn)監(jiān)控varnish緩存服務(wù)器的狀態(tài),Varnish是一款高性能的開(kāi)源HTTP加速器,可以替代Squid、Nginx等服務(wù)器,需要的朋友可以參考下2014-12-12Mac M1安裝mnmp(Mac+Nginx+MySQL+PHP)開(kāi)發(fā)環(huán)境
這篇文章主要介紹了Mac M1安裝mnmp(Mac+Nginx+MySQL+PHP)開(kāi)發(fā)環(huán)境,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2021-03-03基于python發(fā)送郵件的亂碼問(wèn)題的解決辦法
本篇文章小編為大家介紹了,基于python發(fā)送郵件的亂碼問(wèn)題的解決辦法。需要的朋友參考下2013-04-04PHP簡(jiǎn)易延時(shí)隊(duì)列的實(shí)現(xiàn)流程詳解
普通的隊(duì)列是先進(jìn)先出,但是延時(shí)隊(duì)列并不是,而是加上了時(shí)間這一權(quán)重。希望到達(dá)時(shí)間點(diǎn)的先執(zhí)行。從某種意義上來(lái)講,延遲隊(duì)列的結(jié)構(gòu)并不像一個(gè)隊(duì)列,而更像是一種以時(shí)間為權(quán)重的有序堆結(jié)構(gòu)2022-11-11