php 导出csv文件
2019獨角獸企業重金招聘Python工程師標準>>>
function?export_csv($filename,$data)?{?header("Content-type:text/csv");?header("Content-Disposition:attachment;filename=".$filename);?header('Cache-Control:must-revalidate,post-check=0,pre-check=0');?header('Expires:0');?header('Pragma:public');?echo?$data;? }??
?
if(!empty($rows)){
??????????? include(PLUS_PATH."city.cache.php");
?????? ?
??????????? foreach( $rows as $key => $val ){
??????????????? switch ($val['status']){
??????????????????? case 0 :
??????????????????????? $rows[$key]['status_msg'] = '未跟進';
??????????????????????? break;
??????????????????? case 1 :
??????????????????????? $rows[$key]['status_msg'] = '未跟進';
??????????????????????? break;
??????????????????? case 2 :
??????????????????????? $rows[$key]['status_msg'] = '未跟進';
??????????????????????? break;
??????????????????? case 3 :
??????????????????????? $rows[$key]['status_msg'] = '跟進中';
??????????????????????? break;
??????????????????? case 4 :
??????????????????????? $rows[$key]['status_msg'] = '跟進成功';
??????????????????????? break;
??????????????????? case 5 :
??????????????????????? $rows[$key]['status_msg'] = '放棄跟進';
??????????????????????? break;
??????????????????? default:
??????????????????????? break ;
??????????????? }
?????????????? ?
??????????????? $company_name = iconv('utf-8','gb2312',$val['company_name']); //中文轉碼
??????????????? $connecter_one = iconv('utf-8','gb2312',$val['connecter_one']); //中文轉碼
??????????????? $connecter_one_phone = iconv('utf-8','gb2312',$val['connecter_one_phone']); //中文轉碼
??????????????? $connecter_name = iconv('utf-8','gb2312',$_SESSION["name"]); //中文轉碼
?????????????? ?
??????????????? $status_msg = iconv('utf-8','gb2312',$rows[$key]['status_msg']); //中文轉碼
??????????????? $up_time = iconv('utf-8','gb2312',date('Y-m-d h:i:s',$val['up_time'])); //中文轉碼date('Y-m-d h:i:s',$val['up_time']);
????????????? ?
??????????????? $str .= $company_name.",".$connecter_one.",".$connecter_one_phone.",".$connecter_name.",".$status_msg.",".$up_time."\n"; //用引文逗號分開
?????????????? ?
??????????? }
?????????? ?
??????????? $filename = date('Y-m-d').'-'.$_SESSION['name'].'客戶跟進情況'.'.csv'; //設置文件名
??????????? $this->export_csv($filename,$str); //導出
??????? }
?
?
注意:要用同步的方式調用。不能用異步的方式調用哦
轉載于:https://my.oschina.net/u/588516/blog/785561
總結
以上是生活随笔為你收集整理的php 导出csv文件的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Nginx使用SSL配置HTTPS
- 下一篇: C# WinForm开发系列 - Too