PHP export Excel sample Sharing, PHP export Excel sample _php tutorial

Source: Internet
Author: User
Tags eol

PHP export Excel sample Sharing, PHP export Excel sample


Download Phpexcel_1.8.0_doc.zip http://phpexcel.codeplex.com/, the extracted folder classes uploaded to the root directory of the site, the contents of the classes directory are as follows:

Export File excel.php

Require_once dirname (__file__). ' /classes/phpexcel.php ';//introduced phpexcel ..... The process of getting data from a database is omitted here, $a as an array to export ... $numArr = array (' A ', ' B ', ' C ', ' D ', ' E ', ' F ', ' G ', ' H ', ' I ', ' J ', ' K ', ' L ', ' M ', ' N ', ' O ', ' P ', ' Q ', ' R ', ' S ', ' T ', ' U ', ' V ', ' W ', ' X ', ' Y ', ' Z ', ' AA ', ' AB ', ' AC ', ' AD ', ' AE ', ' AF ', ' AG ', ' AH ', ' AI ', ' AJ ', ' AK ', ' AL ', ' AM ', ' an ', ' AO ', ' AP ', ' AQ ', ' AR ', ' as ', ' at ', ' AU ', ' AV ', ' AW ', ' AX ', ' AY ', ' AZ ');//Create new Phpexcel object$objphpexcel = new Phpexcel (); $arr = Array (' Order number ', ' Place Time ', ' City ', ' region ', ' Customer name ', ' consignee ', ' Contact phone ', ' delivery address ', ' ERP customer name ', ' Logistics system Customer name ', ' Activity item ', ' brand ', ' model ', ' color ', ' object Flow system model ', ' order quantity ', ' Unit price ', ' collect money ', ' red envelopes ', ' Price guarantee rebate ', ' freight ', ' paid amount ', ' payment method ', ' Order origin ', ' upstream vendor ', ' Whether in warehouse ', ' express face number ', ' Order status ', ' Confirm time ', ' last state confirmation ' Between ', ' description ', ' corresponding business ', ' corresponding customer service ', ' Business message ', ' Order summary ', ' salesman ', ' Contact Way ');//Output header echo date (' H:i:s '), "Add some data", eol;//set newline $OBJPHPE Xcel->getactivesheet ()->getstyle (' H ')->getalignment ()->setwraptext (true); $objPHPExcel Getactivesheet ()->getstyle (' Y ')->getalignment ()->setwraptext (TRUE);//Set the width of the corresponding column $objphpexcel-> SetactivesheetindeX (0)->getcolumndimension (' A ')->setwidth, $objPHPExcel->setactivesheetindex (0), Getcolumndimension (' B ')->setwidth, $objPHPExcel->setactivesheetindex (0)->getcolumndimension (' G ')- >setwidth, $objPHPExcel->setactivesheetindex (0)->getcolumndimension (' H ')->setwidth (40); $ Objphpexcel->setactivesheetindex (0)->getcolumndimension (' I ')->setwidth, $objPHPExcel Setactivesheetindex (0)->getcolumndimension (' J ')->setwidth (15);//output First line $objphpexcel-> Setactivesheetindex (0)->setcellvalue (' A1 ', $arr [0])->setcellvalue (' B1 ', $arr [1])->setcellvalue (' C1 ', $ ARR[2])->setcellvalue (' D1 ', $arr [3])->setcellvalue (' E1 ', $arr [4])->setcellvalue (' F1 ', $arr [5]) Setcellvalue (' G1 ', $arr [6])->setcellvalue (' H1 ', $arr [7])->setcellvalue (' I1 ', $arr [8])->setcellvalue (' J1 ') , $arr [9])->setcellvalue (' K1 ', $arr [ten])->setcellvalue (' L1 ', $arr [11]);//output content for ($i =0; $i
 
  
Setactivesheetindex (0)->setcellvalue ($numArr [0]. ( $i +2), $a [$i] [' ORDER_SN '])->setcellvalue ($NUMARR [1]. ( $i +2), $a [$i] [' add_time '])->setcellvalue ($NUMARR [2]. ( $i +2), $a [$i] [' City '])->setcellvalue ($NUMARR [3]. ( $i +2), $a [$i] [' region_name '])->setcellvalue ($NUMARR [4]. ( $i +2), $a [$i] [company])->setcellvalue ($NUMARR [5]. ( $i +2), $a [$i] [' consignee '])->setcellvalue ($NUMARR [6]. ( $i +2), $a [$i] [' Mobile '])->setcellvalue ($NUMARR [7]. ( $i +2), $a [$i] [' address '])->setcellvalue ($NUMARR [8]. ( $i +2), ")->setcellvalue ($NUMARR [9]. ( $i +2), ")->setcellvalue ($NUMARR [10]. ( $i +2), ")->setcellvalue ($NUMARR [11]. ( $i +2), $a [$i] [' brand_name ']);} Rename Worksheetecho Date (' h:i:s '), "Rename Worksheet", EOL; $dirName = Date ("YMD");//directory name $filename = Date ("Ymdhis"); /filename $objphpexcel->getactivesheet ()->settitle ($fileName);//Set Active sheet Index to the first sheet, so Excel open S this as the first sheet$objphpexcel->setactivesheetindex (0);//Save Excel 2007Fileecho date (' h:i:s '), "Write to Excel2007 format", EOL; $callStartTime = Microtime (True); if (!opendir ('. /excel/'. $dirName)} {mkdir ('.. /excel/'. $dirName);} $objWriter = Phpexcel_iofactory::createwriter ($objPHPExcel, ' Excel2007 '); $objWriter->save ('.. /excel/'. $dirName. ' /'. $fileName. '. Xlsx '); $end = GetCurrentTime (); $spend = $end-$begin; if ($spend >) {echo '; exit;} Header (' location:http://'. $_server[' Http_host '). ' /excel/'. $dirName. ' /'. $fileName. '. Xlsx ');
 


PHP Export Excel

Simply send the Excel header to the browser.
Header ("Content-type:application/vnd.ms-excel");
Header ("Content-disposition:filename=aa.xls");

Complex few words will not be clear.

Urgent PHP export generates Excel code

You can use the Phpexcel to make the output very useful official address: phpexcel.codeplex.com/in the upper right corner of the download using the method: Setoffice2003compatibility (TRUE); Set document Basic Properties $objProps = $objExcel->getproperties (); $objProps->setcreator ("Zeal Li"); $objProps->setlastmodifiedby ("Zeal Li"); $objProps->settitle ("Office XLS Test Document"); $objProps->setsubject (&q ... Remaining full text >>

http://www.bkjia.com/PHPjc/865614.html www.bkjia.com true http://www.bkjia.com/PHPjc/865614.html techarticle PHP export Excel sample Sharing, PHP export Excel sample download Phpexcel_1.8.0_doc.zip http://phpexcel.codeplex.com/, Upload the extracted folder classes to the root directory of the website, ...

  • 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.