Provides two kinds of export Excel Method 1 simplest export Excel header (' Content-type:application/vnd.ms-excel '); The set file type can also change Vnd.ms-excel ' to XML (export XML file) header (' Content-disposition:attachment;filename= ' Cloud Platform User report. xls "); Sets the name of the exported Excel header (' cache-control:max-age=0 '); Echo iconv ("Utf-8", "GBK", "time \ t error code \ t number of occurrences \ t error code meaning \ n"); \ t is a tab \ n is a newline character, foreach ($arr as $key = + $val) {//$arr is the data to be exported echo iconv ("Utf-8", "GBK", Date ("y-m-d", $val ["Time"]). " \ t ". $val [" Error_code "]." \ t ". $val [" num "]." \ t ". $val [" Code_mean "]." \ n "); } 2. Use Phpexcel to export Excel to download the Phpexcel compressed package into your project instance: require_once (' phpexcel.php ') with phpexcel.php and phpexcel compression packages; Refer to these two files require_once (' phpexcel/writer/excel2007.php '); Export Excel $objExcel = new Phpexcel (); $objProps = $objExcel->getproperties (); $objProps->setcreator ("Zeal Li"); $objProps->setlastmodifiedby ("Zeal Li"); $objProps->settitle ("Office XLS Test Document"); $objProps->setsubject ("Office XLS Test Document, Demo"); $objProps->setdescription ("Test document, generated by Phpexcel."); $objPropS->setkeywords ("Office Excel Phpexcel"); $objProps->setcategory ("Test"); $objProps = $objExcel->getproperties (); $objProps->setcreator ("Zeal Li"); $objProps->setlastmodifiedby ("Zeal Li"); $objProps->settitle ("Office XLS Test Document"); $objProps->setsubject ("Office XLS Test Document, Demo"); $objProps->setdescription ("Test document, generated by Phpexcel."); $objProps->setkeywords ("Office Excel Phpexcel"); $objProps->setcategory ("Test"); Sets the current sheet index for subsequent content operations. It is generally only necessary to display a call when multiple sheet are used. By default, Phpexcel automatically creates the first sheet is set sheetindex=0 $objExcel->setactivesheetindex (0); $objActSheet = $objExcel->getactivesheet (); Online Games class//Set the name of the current activity sheet $objActSheet->settitle (' Online game class '); $objActSheet->setcellvalue (' A1 ', ' Game Name '); The first line of data in the first sheet of the generated Excel $objActSheet->setcellvalue (' B1 ', ' specific domain name '); $objActSheet->setcellvalue (' C1 ', ' server description '); $objActSheet->setcellvalue (' D1 ', ' line Properties '); $objActSheet->setcellvalue (' E1 ', ' submitted servicesDevice IP '); $objActSheet->setcellvalue (' F1 ', ' corresponding to optimized routing entries '); $objActSheet->setcellvalue (' G1 ', ' keyword optimization '); $objActSheet->setcellvalue (' H1 ', ' optimized line '); $objActSheet->setcellvalue (' I1 ', ' optimization state '); foreach ($result _webgame as $k 1=> $v 1) {//Traverse data read from the database $objActSheet->setcellvalue (' A '). $k 1+2), $v 1["Gamename"]); $objActSheet->setcellvalue (' B '. ( $k 1+2), $v 1[' domain '); $objActSheet->setcellvalue (' C '. ( $k 1+2), $v 1[' gameserver '); $objActSheet->setcellvalue (' D '. ( $k 1+2), $v 1[' Line_attribute '); $objActSheet->setcellvalue (' E '. ( $k 1+2), $v 1[' server_ip '); $objActSheet->setcellvalue (' F '. ( $k 1+2), $v 1[' Optimize_route '); $objActSheet->setcellvalue (' G '. ( $k 1+2), $v 1[' keyword '); $objActSheet->setcellvalue (' H '. ( $k 1+2), $v 1[' line '); $objActSheet->setcellvalue (' I '. ( $k 1+2), $v 1[' optimize_status '); }//Website class//Add a new worksheet $objExcel->createsheet (); $reource _ready= $objExcel->getsheet (1)->settitle (' website class '); $reource _ready->setcellvalue (' A1 ', ' website name '); $reource _ready->setcellvalue (' B1 ', 'Specific domain name '); $reource _ready->setcellvalue (' C1 ', ' line Properties '); $reource _ready->setcellvalue (' D1 ', ' IP network segment '); $reource _ready->setcellvalue (' E1 ', ' optimized line '); $reource _ready->setcellvalue (' F1 ', ' optimization state '); foreach ($result _website as $k 1=> $v 2) {$reource _ready->setcellvalue (' A '. $k 1+2), $v 2["name"]); $reource _ready->setcellvalue (' B '. ( $k 1+2), $v 2[' domain '); $reource _ready->setcellvalue (' C '. ( $k 1+2), $v 2[' Line_attribute '); $reource _ready->setcellvalue (' D '. ( $k 1+2), $v 2[' IP '); $reource _ready->setcellvalue (' E '. ( $k 1+2), $v 2[' line '); $reource _ready->setcellvalue (' F '. ( $k 1+2), $v 2[' optimize_status '); }//And so you can export Excel that contains multiple sheet
http://www.bkjia.com/PHPjc/477130.html www.bkjia.com true http://www.bkjia.com/PHPjc/477130.html techarticle provides two export Excel methods 1 simplest export Excel header (content-type:application/vnd.ms-excel);//Set file type can also be vnd.ms-excel Change to XML (export XML file) ...