php 导出多个excel并输出压缩文件

本文介绍了一种使用phpExcel库高效地导出多个Excel文件,并将它们打包成压缩文件的方法,简化了多Excel文件处理的复杂性。
set_time_limit(0);
    ob_end_clean();
    header('Content-Encoding: none');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename='.$fileName);
    header('Pragma: no-cache');
    header('Expires: 0');

    //查询数据库中唯一的省份
    $distinct_company = C::t('common_usercompany')->fetch_distinct_company_exportall();
    $arr = [];
    $fileNameArr = array();

    //每个省份导出一个excel
    foreach ($distinct_company as $key => $value) {
        $uids = C::t('common_usercompany')->fetch_all_conpany_users($value);
        $detail = '';
        //excel的header头
        $title = array('UID','用户名','member_type'=> '用户类型','field1' => '','mobile' => '', 'company'=>'公司','company_address' => '公司区域','stock_code'=>'公司代码', 'gender' => '', 'birthyear' => '', 'birthmonth' => '', 'birthday' => '',
            'address' => '',  'bio' => '',  'auth_completed' => '是否验证');
        foreach(C::t('common_member_profile_setting')->range() as $v1) {
            if(isset($title[$v1['fieldid']])) {
                $title[$v1['fieldid']] = $v1['title'];
            }
        }

        //如果该省份下有注册的用户,则输出excel表
        if($uids && is_array($uids)) {
            $arr[] = $uids;
            $allprofile = C::t('common_member_profile')->fetch_all($uids);
            $company = C::t('common_usercompany')->fetch_by_province($value);
            $allusername = C::t('common_member')->fetch_all_by_uid($uids);
            $member_types = get_member_type();

            //生成临时文件
            $filename = $company['province'].'.csv';
            $filename = iconv("UTF-8","GBK//IGNORE",$filename);
            $fp = fopen($filename, 'w');
//            chmod($company['province']. '.csv',777);//修改可执行权限
            //Windows下使用BOM来标记文本文件的编码方式,否则输出的数据乱码
  
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值