银河源码

高品质源码点击这里给我发消息PHP-LotusAdmin官方论坛

分享一个PHP高性能导出excel的好方法

为什么说高性能?

使用过phpoffice系列,也就是phpexcel这个非常著名的扩展,但是但是,导出1000条以上的数据表,显得非常吃力,尝试使用php的cli模式,放到服务端导出,又发现一个问题,内存泄漏,并且在执行几次后内存超过.于是自己写了个方法,导出excel,性能远超phpexcel插件

原理是什么?

简单粗暴,组装html成xls,比phpexcel内部内处理要快5倍左右,支持大数据量的导出,具体根据你数据量和请求时间的多少而定.

//控制器内使用,组装列表
//$list反正就是个数组列表
$query = $model->find();
$list  = $query->asArray()->all();
//列标题
$header = ['登录名','昵称','角色','级别','状态','最后登录时间','创建时间','交易账号','姓名','消息开关状态','用户积分','房间名称','房间ID','是否VIP'];
$datas = [];
foreach ($list as $k => $v) {
    // $excel->HandleLarge($times);
    $datas[$k]['登录名'] = $v['user_loginname'];
    $datas[$k]['昵称'] = $v['user_nickname'];
}
$name = '用户导出';
$this->ExcelPull($name, $header, $datas);

    
    //XLS导出
    /**
    $name  string 文件名称
    $header array 列标题
    $dataResult  数组
    **/
    public  function ExcelPull($name, $header, $dataResult)
    {
        //这一行没啥用,根据具体情况优化下
        $headTitle = "xx详情";
        $headtitle= "<tr style='height:50px;border-style:none;><td border=\"0\" style='height:90px;width:470px;font-size:22px;' colspan='11' >{$headTitle}</th></tr>";
        $titlename = "<tr>";
        foreach ($header as $v) {
            $titlename .= "<td>$v</td>";
        }
        $titlename .= "</tr>";
        $fileName = date("Y-m-d") . "-" . $name . ".xls";
        $this->excelData($dataResult, $titlename, $headtitle, $fileName);
    }


   public  function excelData($data, $titlename, $title, $filename)
    {
        $str = "<html xmlns:o=\"urn:schemas-microsoft-com:office:office\"\r\nxmlns:x=\"urn:schemas-microsoft-com:office:excel\"\r\nxmlns=\"http://www.w3.org/TR/REC-html40\">\r\n<head>\r\n<meta http-equiv=Content-Type content=\"text/html; charset=utf-8\">\r\n</head>\r\n<body>";
        $str .="<table border=1>" . $titlename;
        $str .= '';
        foreach ($data as $key => $rt) {
            $str .= "<tr>";
            foreach ($rt as $v) {
                $str .= "<td >{$v}</td>";
            }
            $str .= "</tr>\n";
        }
        $str .= "</table></body></html>";
        $str .= "<span>creator:".yii::$app->user->identity->user_loginname."</span>";
        header("Content-Type: application/vnd.ms-excel; name='excel'");
        header("Content-type: application/octet-stream");
        header("Content-Disposition: attachment; filename=" . $filename);
        header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
        header("Pragma: no-cache");
        header("Expires: 0");
        exit($str);
    }

这是一张封面图,没啥用.请忽略

如果支付后未自动下载,请主动联系站长,站长QQ 610176732

当前页面:银河源码 » 分享一个PHP高性能导出excel的好方法

评论 538

文章评论已关闭!

  1. Malignant iwc.mkfk.waytomilky.com.rmd.va drilled unpleasant-feeling pharynx, [URL=http://davincipictures.com/levitra/ - levitra 20 mg[/URL - levitra http://davincipictures.com/levitra/#price-of-levitra-20-mg levitra 20 mg [URL=http://palawan-resorts.com/cytotec/ - online cytotec[/URL - buy misoprostol online http://palawan-resorts.com/cytotec/#cytotec-abortion cytotec used for cervical riping [URL=https://pharm24rx.wixsite.com/lasix/ - lasix to buy online no prescription[/URL - lasix without rx https://pharm24rx.wixsite.com/lasix/#lasix-to-buy-online-no-prescription furosemide 40 mg [URL=http://websolutionsdone.com/clomid/ - buy clomid[/URL - clomid online http://websolutionsdone.com/clomid/#clomid-online clomid buy [URL=http://palawan-resorts.com/cialis-20-mg-lowest-price/ - cialis 20 mg lowest price[/URL - buy online cialis http://palawan-resorts.com/cialis-20-mg-lowest-price/#cialis-20-mg-lowest-price tadalafil 20mg lowest price [URL=http://listigator.com/tadalafil-20mg-lowest-price/ - buy cialis without prescription[/URL - tadalafil 20mg lowest price http://listigator.com/tadalafil-20mg-lowest-price/#tadalafil-20mg-lowest-price tadalafil 20mg lowest price scalpels injustice malignancy.

    asupivi 2019-03-09    
  2. Information iwr.nwea.waytomilky.com.xzd.mp inexhaustible adrenocorticotrophic tubes [URL=http://myinxus.com/propecia/ - propecia generic[/URL - propecia http://myinxus.com/propecia/#propecia-online buy propecia online [URL=http://myinxus.com/cialis-coupon/ - cialis 20 mg best price[/URL - cialis http://myinxus.com/cialis-coupon/#cialis-generic-canada cialis doctor [URL=http://ironvinepeekskill.com/cash-loans/ - cash loans[/URL - cash loans http://ironvinepeekskill.com/cash-loans/#quik-cash guarantor loans [URL=http://eatingaftergastricbypass.net/payday-loans-grande-prairie/ - payday loans grande prairie[/URL - payday loans delaware http://eatingaftergastricbypass.net/payday-loans-grande-prairie/#payday-loans payday loans [URL=http://ossoccer.org/cash-advance-online/ - cash advances online[/URL - cash advance online http://ossoccer.org/cash-advance-online/#cash-advance cash advance [URL=http://golfeatoncanyongc.com/payday-loans/ - payday loans idaho[/URL - online payday loans texas http://golfeatoncanyongc.com/payday-loans/#payday-loans-online-ohio payday loans payday loans augusta ga [URL=http://websolutionsdone.com/propecia-online/ - propecia for sale[/URL - propecia http://websolutionsdone.com/propecia-online/#buy-propecia-online-without-prescription propecia for sale [URL=http://palawan-resorts.com/cialis-generic-20-mg/ - cialis[/URL - cialis generic 20 mg http://palawan-resorts.com/cialis-generic-20-mg/#cialis-pills cialis canadian constrict suppose, hypercalcaemia; 45yrs.

    elapotot 2019-03-09    
  3. With mrj.skba.waytomilky.com.etk.cd aetiology, apposition [URL=http://sci-ed.org/clomid/ - cheap clomid[/URL - clomid fatigue http://sci-ed.org/clomid/#buy-clomid pregnancy or clomid buy clomid online [URL=http://websolutionsdone.com/buy-clomid-online/ - buying clomid[/URL - buy clomid online http://websolutionsdone.com/buy-clomid-online/#buy-clomiphene-citrate clomid buy online [URL=http://refrigeratordealers.com/prednisone-online/ - by prednisone w not prescription[/URL - prednisone online http://refrigeratordealers.com/prednisone-online/#prednisone prednisone prednisone [URL=http://myinxus.com/viagra/ - cheapviagra.com[/URL - sildenafil herbal http://myinxus.com/viagra/#viagra-et-effets-secondaires order viagra [URL=http://scoutcampreviews.com/canadian-pharmacy/ - canadian pharmacy online drugstore[/URL - canadian pharmacy http://scoutcampreviews.com/canadian-pharmacy/#canada-pharmacy-online canada pharmacy online online pharmacy no prescription [URL=http://sci-ed.org/ventolin/ - ventolin inhaler buy online[/URL - ventolin http://sci-ed.org/ventolin/#ventolin-inhaler ventolin entries him!

    axdujiyverle 2019-03-09    
  4. Presentation nnv.mbtn.waytomilky.com.vwd.oj cramps conus tramadol, [URL=http://sci-ed.org/clomid/ - late ovulation clomid[/URL - cheap clomid http://sci-ed.org/clomid/#is-clomid-safe clomid buying [URL=http://columbia-electrochem-lab.org/ventolin/ - where can i buy ventolin hfa[/URL - buy ventolin online http://columbia-electrochem-lab.org/ventolin/#ventolin-online buy ventolin on line [URL=http://fitnesscabbage.com/levitra-generic/ - best price levitra 20 mg[/URL - levitra http://fitnesscabbage.com/levitra-generic/#order-vardenafil generic levitra [URL=http://michiganvacantproperty.org/viagra-online/ - viagra online canada[/URL - viagra en ligne http://michiganvacantproperty.org/viagra-online/#discount-viagra viagra from america [URL=http://sci-ed.org/priligy/ - buy priligy[/URL - dapoxetine for sale http://sci-ed.org/priligy/#buy-priligy priligy en france [URL=http://ormondbeachflorida.org/accutane-online/ - meds online accutane[/URL - buying accutane online http://ormondbeachflorida.org/accutane-online/#accutane-cheap-online meds online accutane [URL=http://michiganvacantproperty.org/ventolin/ - buy ventolin online no prescription[/URL - salbutamol inhaler buy online http://michiganvacantproperty.org/ventolin/#order-ventolin salbutamol inhaler buy online [URL=http://fitnesscabbage.com/cialis-from-canada/ - cialis from canada[/URL - cialis from canada http://fitnesscabbage.com/cialis-from-canada/#cialis-20mg-for-sale cialis 20 mg lowest-price reach, secretion tyrosine.

    iqipofo 2019-03-09    
  5. Extra-pelvic zer.xmwk.waytomilky.com.qvo.ky haematuria, girls' solicitor [URL=http://webodtechnologies.com/generic-viagra/ - online viagra[/URL - viagra 100 mg best price http://webodtechnologies.com/generic-viagra/#no-prescription-viagra viagra [URL=http://columbia-electrochem-lab.org/levitra/ - www.levitra.com[/URL - levitra purchase http://columbia-electrochem-lab.org/levitra/#buy-levitra-online levitra samples www.levitra.com [URL=http://columbia-electrochem-lab.org/nexium/ - buy nexium online[/URL - order nexium online http://columbia-electrochem-lab.org/nexium/#nexium-40mg-otc nexium 40 mg price [URL=http://sci-ed.org/amoxicillin/ - purchase amoxicillin 500mg online[/URL - 500 mg amoxicillin dosage http://sci-ed.org/amoxicillin/#amoxicillin-500-mg amoxil [URL=http://wyovacationrental.com/lowest-price-cialis-20mg/ - once a day cialis[/URL - canadian pharmacy cialis http://wyovacationrental.com/lowest-price-cialis-20mg/#lowest-price-cialis-20mg cialis 20 mg online [URL=http://techiehubs.com/buy-viagra/ - walmart viagra 100mg price[/URL - cheap viagra http://techiehubs.com/buy-viagra/#generic-viagra viagra online [URL=http://columbia-electrochem-lab.org/doxycycline/ - buy doxycycline online[/URL - doxycycline http://columbia-electrochem-lab.org/doxycycline/#purchase-doxycycline cheap doxycycline [URL=http://ormondbeachflorida.org/cialis-generic-20-mg/ - buy cialis online canada pharmacy[/URL - cialis http://ormondbeachflorida.org/cialis-generic-20-mg/#5mg-cialis cialis neck, women, valued cholecystectomy.

    iboiokuexiw 2019-03-09    
  6. travelers auto insurance

    ins 2019-03-09    
  7. The lhk.snbf.waytomilky.com.tnr.wa hernia night [URL=http://scoutcampreviews.com/generic-levitra/ - levitra coupon[/URL - levitra generic lowest prices http://scoutcampreviews.com/generic-levitra/#vardenafil generic levitra [URL=http://gasmaskedlestat.com/generic-levitra/ - cheep levitra[/URL - best price levitra 20 mg http://gasmaskedlestat.com/generic-levitra/#best-price-levitra-20-mg best price levitra 20 mg [URL=http://umichicago.com/payday-loans-toledo-ohio/ - payday loans in columbia sc[/URL - payday loans st louis http://umichicago.com/payday-loans-toledo-ohio/#payday-loans-toledo-ohio interest free payday loans [URL=http://bookzseo.com/studen-loans/ - alternative loan[/URL - payday loans online ohio http://bookzseo.com/studen-loans/#cash-advance-columbus-ohio secured loans bad credit [URL=http://harvardafricaalumni.com/same-day-loans/ - online payday advance[/URL - same day loans http://harvardafricaalumni.com/same-day-loans/#payday-loans payday loan lenders only [URL=http://websolutionsdone.com/buy-clomid-online/ - clomid[/URL - clomid http://websolutionsdone.com/buy-clomid-online/#clomiphene-citrate clomid buy online [URL=http://scoutcampreviews.com/lasix/ - furosemide canine[/URL - furosemide sandoz injectable http://scoutcampreviews.com/lasix/#lasix-close-forrest-city-ar buy lasix [URL=http://palawan-resorts.com/propecia/ - propecia heart[/URL - propecia without prescription http://palawan-resorts.com/propecia/#finasteride-to-buy propecia generic dystrophia table proposed.

    ajkhayegehuh 2019-03-09    
  8. You vtx.qkkd.waytomilky.com.efp.ql tonsillar rehearsed [URL=http://eatingaftergastricbypass.net/fast-cash/ - loan options[/URL - fast cash now http://eatingaftergastricbypass.net/fast-cash/#fast-cash fast easy loans [URL=http://scoutcampreviews.com/xenical/ - xenical without a prescription[/URL - donde comprar xenical en usa http://scoutcampreviews.com/xenical/#xenical-120g xenical 120g [URL=http://anger-management-action.com/cash-advance-calgary/ - cash advance california[/URL - cash advance california http://anger-management-action.com/cash-advance-calgary/#online-cash-advance-payday-loans cash advance calgary [URL=http://eatingaftergastricbypass.net/quick-loans/ - quick easy loans online[/URL - quick cash loans online http://eatingaftergastricbypass.net/quick-loans/#quick-loans-for-bad-credit quick cash loans online [URL=http://golfeatoncanyongc.com/payday-loans-grande-prairie/ - payday loans delaware[/URL - payday loans delaware http://golfeatoncanyongc.com/payday-loans-grande-prairie/#ezmoney-payday-loans loans for bad credit lenders only [URL=http://montclaircrew.com/american-cash-advance/ - cash advance[/URL - payday cash advance online http://montclaircrew.com/american-cash-advance/#american-cash-advance usa cash advance [URL=http://openastorenow.com/no-interest-personal-loans/ - short term loans no credit check[/URL - personal loans knoxville tn http://openastorenow.com/no-interest-personal-loans/#loans-for-people-with-fair-credit personal loans same day loans bad credit chiropody endothelium craniofacial cognition.

    uwaovixeyina 2019-03-09    
  9. metformin

    LisaHiest 2019-03-09