First go to download Phpexcel class, address http://phpexcel.codeplex.com/
Method introduces this extension class as the first step
1 Vendor (' Phpexcel ');
The second part is the method, the following simple implementation method
1 Public functionPhpexcel ()2 {3 //$list =array (Array (' DFCDF ', ' Test ', ' dfdfdsfd ', ' DFD ', ' dfdf '), Array (' DFDSF ', ' 51 planner ', ' dfdsfd ', ' efed ', ' dfdf '));4 $list= Session (' Cash_list ');5 $phpExcel=New\phpexcel ();6 $phpExcel-getProperties ()7->setcreator (' Shulaibao ')//Create Person8->setlastmodifiedby (' Shulaibao ')//Last modified person9->settitle (' Office ' XLSX Test Document ')//titleTen->setsubject (' Office ' XLSX Test Document ')//Topics One->setdescription (' Test document for Office ' XLSX, generated using PHP classes. ')//Description A->setkeywords (' Office OpenXML PHP ') -->setcategory (' Test Result file '); - //set the current sheet the $phpExcel->setactivesheetindex (0); - //set up the table header - $phpExcel-Getactivesheet () -->setcellvalue (' A1 ', ' user ') +->setcellvalue (' B1 ', ' No. ') -->setcellvalue (' C1 ', ' Merchant Order number ')) +->setcellvalue (' D1 ', ' payment order number ')) A->setcellvalue (' E1 ', ' Send Time '); at foreach($list as $key=$value) { - $phpExcel-Getactivesheet () -->setcellvalue (' A '. ($key+ 2),$value[' User_login ']) -->setcellvalue (' B '). ($key+ 2),$value[' Re_user_name ']) -->setcellvalue (' C '). ($key+ 2),$value[' Mcn_billno ']) -->setcellvalue (' D '. ($key+ 2),$value[' Payment_no ']) in->setcellvalue (' E '. ($key+ 2),Date(' Y-m-d h:i:s ',$value[' Send_time '])); - } to //set the title of the sheet + $phpExcel->getactivesheet ()->settitle (' Send record '); - //create a file format to write to an object instance, uncomment the //$objWriter = Phpexcel_iofactory::createwriter ($phpExcel, ' Excel5 '); * //$objWriter = new \phpexcel_writer_excel5 ($phpExcel); For other version formats $ //$objWriter = new phpexcel_writer_excel2007 ($objExcel);///For 2007 formatsPanax Notoginseng $objWriter=New\phpexcel_writer_excel5 ($phpExcel); - //Set file name the $filename=Date(' Y-m-d h:i:s ', Time()) . ' _ Red envelopes send records. xls '; + //Set Header A //Ob_clean (); the //Flush (); + Header("Content-type:application/force-download"); - Header("Content-type:application/octet-stream"); $ Header("Content-type:application/download"); $ Header(' Content-disposition:inline;filename= '.$filename. ‘"‘); - Header("Content-transfer-encoding:binary"); - Header("Last-modified:".)gmdate("D, D M Y h:i:s"). "GMT"); the Header("Cache-control:must-revalidate, post-check=0, pre-check=0"); - Header("Pragma:no-cache");Wuyi $objWriter->save (' Php://output '); the die();//TerminationExecution -}
PHP for Excel Export