PHP Excel export example sharing, php excel export example

Source: Internet
Author: User
Tags eol php excel zip extension

PHP Excel export example sharing, php excel export example

Download phpexcel_1.8.0_doc.zip Extension:

Export File Excel. php

Require_once dirname (_ FILE __). '/Classes/PHPExcel. php '; // introduce PHPExcel ..... the process of retrieving data from the database is omitted here. $ a is the array to be exported ...... $ 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', 'A',' AB ', 'ac', 'ad', 'AE', 'af', 'ag', 'Ah', 'ai', 'aj ', 'ak', 'al ', 'am', 'any', 'ao', 'ap ', 'aq', 'ar ', 'as', 'at', 'au', 'av ', 'aw', 'ax', 'ay', 'az'); // Create new PHPExcel object $ objPHPExcel = ne W PHPExcel (); $ arr = array ('order No. ', 'order time', 'city', 'region', 'customer name', 'consignee ', 'Contact phone', 'shipping address', 'erp customer name', 'logistics system customer name', 'activity Project', 'brand', 'model', 'color ', 'logistics System Model ', 'order quantity', 'unit price', 'collection of money ', 'hongba', 'price-preserving rebates', 'freight ', 'actual amount of paid ', 'payment method ', 'order source', 'upstream manufacturers', 'warehouse?', 'waybill No. ', 'order status', 'confirmation time ', 'Last status confirmation time', 'description', 'corresponding business', 'corresponding service', 'Merchant message', 'order digest ', 'salesman ', 'Contact information'); // output the title echo date ('H: I: s'), "Add some data", EOL; // set the line feed $ objPHPExcel-> 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 (15 ); $ objPHPExcel-> setActiveSheetIndex (0)-> getColumnDimension ('B')-> setWidth (20); $ objPHPExcel-> setActiveSheetIndex (0)-> getColumnDimension ('G ') -> setWidth (15); $ objPHPExcel-> setActiveSheetInde X (0)-> getColumnDimension ('H')-> setWidth (40); $ objPHPExcel-> setActiveSheetIndex (0)-> getColumnDimension ('I ') -> setWidth (15); $ objPHPExcel-> setActiveSheetIndex (0)-> getColumnDimension ('J')-> setWidth (15 ); // output the 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])-> setCellV Alue ('f1', $ arr [5])-> setCellValue ('g1', $ arr [6])-> setCellValue ('h1 ', $ arr [7]) -> setCellValue ('i1', $ arr [8])-> setCellValue ('j1', $ arr [9])-> setCellValue ('k1 ', $ arr [10])-> setCellValue ('l1', $ arr [11]); // output content for ($ I = 0; $ I <count ($ a); $ I ++) {$ objPHPExcel-> setActiveSheetIndex (0)-> setCellValue ($ numArr [0]. ($ I + 2), $ a [$ I] ['order _ sn '])-> setCellValue ($ numArr [1]. ($ I + 2), $ a [$ I] ['add _ time'])-> setCellValue ($ nu MArr [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 "); // file name $ objPHPExcel-> getActiveSheet ()-> setTitle ($ fileName); // Set active sheet index to the first sheet, so Excel opens this as the first sheet $ objPHPExcel-> setActiveSheetIndex (0); // Save Excel 2007 fileech O 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. '/'.w.filename.'.xlsx'); $ end = getCurrentTime (); $ spend = $ end-$ begin; if ($ spend> 30) {echo '<script> if (confirm ("execution timeout! ") {Window. history. back (-1) ;}</script> '; exit;} header ('location: http ://'. $ _ SERVER ['HTTP _ host']. '/excel /'. $ dirName. '/'.w.filename.'.xlsx ');


Php excel Export

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

A complicated slogan may not be clear.

Urgent php export to generate excel code

You can use phpexcel for output. The official address phpexcel.codeplex.com/has the download usage method in the upper right corner: <? // Set the include path set_include_path ('. '. PATH_SEPARATOR. 'd: \ Zeal \ PHP_LIBS '. PATH_SEPARATOR. get_include_path ();/*** The following is an example. It is optional for rows starting with //. Open the comment of the corresponding row as needed. * If Excel5 is used, the output content should be GBK encoded. */Require_once 'phpexcel. php '; // uncomment // require_once 'phpexcel/Writer/excel5.php '; // used for other earlier versions of xls // or /// require_once 'phpexcel/Writer/excel2007.php '; // used for excel-2007 format // create an instance for processing objects $ objExcel = new PHPExcel (); // create an instance for writing objects in file format, uncomment // $ objWriter = new PHPExcel_Writer_Excel5 ($ objExcel); // used for other version formats // or /// $ objWriter = new PHPExcel_Writer_Excel2007 ($ objExcel ); // for the 2007 format // $ objWriter-> setOffice2003Compatibility (true ); //*************************************/ /set the basic attributes of the document $ objProps = $ objExcel-> getProperties (); $ objProps-> setCreator ("Zeal Li"); $ objProps-> setLastModifiedBy ("Zeal Li"); $ objProps-> setTitle ("Office XLS Test Document "); $ objProps-> setSubject (& q ...... remaining full text>
 

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.