TP5 Excel Export Class

Source: Internet
Author: User
Tags export class

1. Introduction of Loader

 use Think\loader;

2. Export method:

/** * Excel Table Export * @param string $fileName file name * @param array $HEADARR header name * @param array $data data to be exported * @author static 7*/functionExcelexport ($fileName= ",$HEADARR= [],$data= [],$widths=[]) {    $fileName=Iconv("UTF-8", "Gb2312//ignore", @$fileName); $fileName. = ". xls"; Loader:: Import (' Phpexcel.phpexcel '); Loader:: Import (' PHPExcel.PHPExcel.IOFactory.PHPExcel_IOFactory '); $objPHPExcel=New\phpexcel (); $objPHPExcel-getProperties (); A=Ord(' A ');// $    $key 2=Ord("@");// -    foreach($HEADARR  as $v) {        if(A>Ord("Z"))        {            $colum=CHR(Ord("A")).CHR(++$key 2);//more than 26 letters AA1,AB1,AC1,AD1 ... BA1,BB1 ...}Else{            $colum=CHR(A++); }        $objPHPExcel->setactivesheetindex (0)->setcellvalue ($colum. ' 1 ',$v); }    $column= 2; $objActSheet=$objPHPExcel-Getactivesheet (); foreach($data  as $key=$rows) {//Line Write        A=Ord(' A ');//start from a again        $key 2=Ord("@");// -            foreach($rows  as $keyName=$value) {//Column Write                if(A>Ord("Z"))                {                    $colum=CHR(Ord("A")).CHR(++$key 2);//more than 26 letters AA1,AB1,AC1,AD1 ... BA1,BB1 ...}Else{                    $colum=CHR(A++); }                $objActSheet->setcellvalue ($colum.$column,$value); }        $column++; }    //Table Width    if(Count($widths)){        A=Ord(' A ');//start from a again        $key 2=Ord("@");// -        foreach($widths  as  $value) {//Column Write            if(A>Ord("Z"))            {                $colum=CHR(Ord("A")).CHR(++$key 2);//more than 26 letters AA1,AB1,AC1,AD1 ... BA1,BB1 ...}Else{                $colum=CHR(A++); }            $objActSheet->getcolumndimension ($colum)->setwidth ($value); }    }    $objWriter= \phpexcel_iofactory::createwriter ($objPHPExcel, ' Excel5 '); //$objWriter->save ('./excelfile/'. $fileName);    Header(' Content-type:application/vnd.ms-excel ');//tell the browser to output the Excel03 file    Header(' Content-disposition:attachment;filename= '.$fileName.‘"‘);//tell the browser the name of the output file (file download)    Header(' cache-control:max-age=0 ');//Disable Caching    $objWriter->save ("Php://output");}

3. Call

Organize display data
           $data[$k[' Seller ']=db::table (' Ims_bj_shopn_member ')->where (' id ',$v[' StaffID ']) ->value (' Realname '); $data[$k[' Sign ']=$v[' Sign ']; $data[$k[' title ']=$v[' title ']; $data[$k[' BSc ']=db::table (' sys_departbeauty_relation ')->alias (' R ')Join[' sys_department ' = ' d '], ' r.id_department=d.id_department ', ' left ')->where (' R.id_beauty ',$v[' StoreID ']) ->value (' D.st_department '); $data[$k[' order_sn ']= ' \ t '.$v[' ORDER_SN ']. " \ t "; $data[$k[' P_name ']=$v[' P_name ']; $data[$k[' P_price ']=$v[' Tuan_price ']; $data[$k[' Insert_time ']=Date(' Y-m-d h:i:s ',$v[' Insert_time ']); $data[$k[' Success_time ']=Date(' Y-m-d h:i:s ',$v[' Success_time ']); $data[$k[' Status ']=$statusText; $data[$k[' Fqr_pay ']=$sonList[0] [' Pay_price ']; $data[$k[' Fqr_tel ']=$sonList[0] [' Mobile ']; $data[$k[' Cantuan1 ']=$sonList[1] [' Realname ']; $data[$k[' Cantuan1_tel ']=$sonList[1] [' Mobile ']; $data[$k[' Cantuan1_pay ']=$sonList[1] [' Mobile ']?$sonList[1] [' Pay_price ']: '; $data[$k[' Cantuan1_num ']=$sonList[1] [' Join_num ']; $data[$k[' Cantuan2 ']=$sonList[2] [' Realname ']; $data[$k[' Cantuan2_tel ']=$sonList[2] [' Mobile ']; $data[$k[' Cantuan2_pay ']=$sonList[2] [' Mobile ']?$sonList[2] [' Pay_price ']: '; $data[$k[' Cantuan2_num ']=$sonList[2] [' Join_num '];; $data[$k[' Cantuan3 ']=$sonList[3] [' Realname ']; $data[$k[' Cantuan3_tel ']=$sonList[3] [' Mobile ']; $data[$k[' Cantuan3_pay ']=$sonList[3] [' Mobile ']?$sonList[3] [' Pay_price ']: '; $data[$k[' Cantuan3_num ']=$sonList[3] [' Join_num '];; $searchOrder=db::name (' tuan_list ')->where ([' Create_uid ' =$v[' Create_uid '], ' status ' =>2])->wheretime (' Begin_time ', ' < ',$v[' Begin_time ']) -Count(); $data[$k[' Is_first ']=$searchOrder? 0:1; $data[$k[' Number ']=$join _num; $seaMap[' List.create_uid ']=Array(' Neq ',$v[' Create_uid ']); $seaMap[' List.status ']=Array(' eq ', 2); $seaMap[' List.order_sn ']=Array(' Neq ',$v[' ORDER_SN ']); $seaMap[' Order.uid ']=Array(' eq ',$v[' Create_uid ']); $searchJoinOrder=db::name (' Tuan_order ')->alias (' order ')Join(' tuan_list list ', ' order.parent_order=list.order_sn ', ' left ')->where ($seaMap)->wheretime (' Order.insert_time ', ' < ',$v[' Begin_time ']) -Count(); $data[$k[' Is_join ']=$searchJoinOrder? 1:0;
Call Export
$filename= "List of consolidation orders".Date(' Ymdhis '); $header=Array(' Event sponsor ', ' The Beautician ', ' Store code ', ' Store name ', ' Office ', ' purchase order number ', ' Buy goods ', ' total merchandise price ', ' launch time ', ' group Time ', ' Purchase status ', ' Initiator payment amount ', ' Initiator mobile number ', ' Participant 1 ' ', ' mobile number ', ' Payment amount ', ' 1 extension guest Liuke ', ' 2 ' participants ', ' mobile number ', ' Payment amount ', ' 2 extension liuke ', ' Mission person 3 ', ' Mobile phone number ', ' Payment amount ', ' Participant 3 extension guest Liuke ', ' sponsor first launch ', ' number of participants ', ' Have you ever been in a group? '); $widths=Array(' 15 ', ' 20 ', ' 20 ', ' 30 ', ' 30 ', ' 30 ', ' 60 ', ' 10 ', ' 20 ', ' 20 ', ' 20 ', ' 20 ', ' 20 ', ' 20 ', ' 20 ', ' 20 ', ' 20 ', ' 20 ', ' 20 ', ' 20 ' , ' 20 ', ' 20 ', ' 20 ', ' 20 ', ' 20 ', ' 20 '); if($data) {Excelexport ($filename,$header,$data,$widths);//Generate Data}

TP5 Excel Export Class

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.