php 導出Excel 不用安裝插件、開啟配置
阿新 • • 發佈:2018-11-17
地址 desc func select() iconv esc 銀行 expires mon
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; } //csv導出 /* * 導出Excel */ public function output() { $org = Db::name('organization')->select(); $list['one'] = Db::name('transfer_flow')->order('add_time desc')->select(); foreach ($list['one'] as $k => $v) { foreach ($org as $kk => $vv) { if ($v['org_id'] == $vv['id']) { $list['one'][$k]['org_id'] = $vv['name']; } } if ($v['pay_type'] === 'WX') { $list['one'][$k]['pay_type'] = '微信'; } else if ($v['pay_type'] === 'A') { $list['one'][$k]['pay_type'] = '支付寶'; } else { $list['one'][$k]['pay_type'] = '銀行轉賬'; } } $str = "訂單號,加盟商,金額,支付方式,添加時間\n"; $str = iconv('utf-8','gb2312',$str); foreach($list['one'] as $k => $v){ $order_no = iconv('utf-8','gb2312',$v['order_no']); $org_id = iconv('utf-8','gb2312',$v['org_id']); $pay_type = iconv('utf-8','gb2312',$v['pay_type']); $str .= $order_no . ',' . $org_id . ',' . $v['money'] . ',' . $pay_type . ',' . $v['add_time'] . "\n"; } $filename = '財務管理_'.date('Ymd').'.csv'; //設置文件名 $this->export_csv($filename,$str); //導出 } 導出csv
原文地址:https://segmentfault.com/a/1190000016116593
php 導出Excel 不用安裝插件、開啟配置