php 导出Excel 不用安装插件、开启配置

均衡侠
• 阅读 2034
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
点赞
收藏
评论区
推荐文章
Easter79 Easter79
3年前
vue 使用axios 出现跨域请求的两种解决方法
最近在使用vueaxios发送请求,结果出现跨域问题,网上查了好多,发现有好几种结局方案。1:服务器端设置跨域header(“AccessControlAllowOrigin:\”);header(“AccessControlAllowHeaders:contenttype”);header(“AccessCont
Stella981 Stella981
3年前
IE iframe跨域访问cookie丢失解决方法
问题描述:IE浏览器加载Iframe跨域访问后Cookie丢失,用户登录状态失效解决方法:在PHP中加入以下代码即可解决header("AccessControlAllowOrigin:");header("AccessControlAllowCredentials:true");head
Stella981 Stella981
3年前
PHP导入导出EXCELl,CSV
PHP导入导出Excel,CSVHTML<formaction"{:U('Admin/Unit/importcsv')}"method"post"name"myform"id"myform"enctype"multipart/formdata"<input
Stella981 Stella981
3年前
PHP、golang 如何播放mp4文件
<?phpfunctionPutMovie($file){header("Contenttype:video/mp4");header("AcceptRanges:bytes");$sizefilesize($file);if(is
Stella981 Stella981
3年前
Discuz 中 ajaxget,ajaxpost 返回值没有显示到指定的区域中
1、需按下面的格式写(需导入require'./source/class/class\_core.php';)includetemplate('common/header\_ajax');echo'jack088';includetemplate('common/footer\_ajax');2、可能是jQuery与Discuz
Wesley13 Wesley13
3年前
PHP创建多级树型结构
<!lang:php<?php$areaarray(array('id'1,'pid'0,'name''中国'),array('id'5,'pid'0,'name''美国'),array('id'2,'pid'1,'name''吉林'),array('id'4,'pid'2,'n
Stella981 Stella981
3年前
PHP Header失效的原因分析
在PHP中用header("location:test.php")进行跳转要注意以下几点:1、location和“:”号间不能有空格,否则会出错。2、在用header前不能有任何的输出,包括include的页面中标签“?”后不能有空格!!3、header后的PHP代码还会被执行。续:问题:
Stella981 Stella981
3年前
Android蓝牙连接汽车OBD设备
//设备连接public class BluetoothConnect implements Runnable {    private static final UUID CONNECT_UUID  UUID.fromString("0000110100001000800000805F9B34FB");
Wesley13 Wesley13
3年前
mysql存储引擎MYISAM和INNODB对比测试
测试源码:header('Contenttype:text/html;charsetutf8;');//for($num0;$num<8;$num){insert();insert(false);//}functioninsert($myisamtrue)
Wesley13 Wesley13
3年前
PHP验证码无法显示的原因
一、如果是utf8,就有可能是BOM没有清除二、在Header("Contenttype:image/PNG");之前有输出三、第一行PHP隐藏了代码,如空格,回车等。解决代码:$image_width70;//设置图像宽度$image_height18;
Wesley13 Wesley13
3年前
ES6之路第三篇:字符串的扩展
字符的Unicode表示法1"\u{20BB7}"2//"𠮷"34"\u{41}\u{42}\u{43}"5//"ABC"67lethello123;8hell\u{6F}//123910'\u{