Export Excel in PHP. When PHP exports Excel to develop a Mall website, the customer needs a function for exporting reports. I use PHPExcel to implement this function. Download phpexcel_1.8.0_doc.zip, unzip it, and export the PHP file to Excel.
When developing a Mall website, the customer needs a report export function. I use PHPExcel to implement this function.
Download phpexcel_1.8.0_doc.zip and upload the Classes in the decompressed folder to the root directory of the website. the contents in the Classes directory are as follows:
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 = new PHPExcel (); $ arr = array ('Order No ', 'order time ', 'city', 'region', 'customer name', 'consignee', 'Contact number', 'shipping address', 'erp customer name ', 'logistics system customer name', 'activity project', 'brand', 'model', 'Color', 'logistics system model', 'Order quantity ', 'unit price ', 'pay-as-you-go users', 'hongba', 'Price rebates ', 'Shipping', 'amount received', 'payment method ', 'Order source', 'Upstream Manufacturers ', 'In warehouse? ', 'waybill no.', 'Order status', 'confirmation time', 'Last status confirmation time', 'Description', 'corresponding service ', 'corresponding to customer service', 'Merchant message', 'Order summary', 'Salesman', 'Contact information ');
// Output 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-> setActiveSheetIndex (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])-> setCellValue ('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
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'])-> setCellVa Lue ($ 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 acti Ve sheet index to the first sheet, so Excel opens this as the first sheet $ objPHPExcel-> setActiveSheetIndex (0); // Save Excel 2007 fileecho 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 ');
Http://www.bkjia.com/PHPjc/871197.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/871197.htmlTechArticlePHP export Excel in the development of a mall site, the customer needs a report export function, I use PHPExcel to achieve this function. Download phpexcel_1.8.0_doc.zip and unzip it...