How long does phpexcel export data?

Source: Internet
Author: User
It takes 20 seconds to export 7000 pieces of data in phpexcel. I got it wrong.
Function exportExcel ($ data_array, $ array, $ filename) {$ letters_arr = array ('1' => 'A', '2' => 'B ', '3' => 'C', '4' => 'D', '5' => 'e', '6' => 'F ', '7' => 'G', '8' => 'h', '9' => 'I', '10' => 'J ', '11' => 'K', '12' => 'L', '13' => 'm', '14' => 'N ', '15' => 'O', '16' => 'P', '17' => 'Q', '18' => 'R ', '19' =>'s ', '20' => 'T', '21' => 'u', '22' => 'V ', '23' => 'W', '24' => 'X', '25' => 'y', '26' => 'Z ', '27' => 'A', '28' => 'AB', '29' => 'AC', '30' => 'AD ', '31' => 'AE', '32' => 'AF', '33' => 'AG', '34' => 'ah ', '35' => 'Ai', '36' => 'AJ ', '37' => 'AK', '38' => 'Al ', '39 '=> 'AM', '40' => 'A', '41 '=> 'ao', '42' => 'AP ', '43 '=> 'Aq', '44' => 'ar ', '45' => 'as', '46' => 'at ', '47' => 'au ', '47' => 'Av', '49' => 'aw', '50' => 'Ax ', '51 '=> 'ay', '52' => 'az',); foreach ($ data_array as $ data) {$ a = array (); foreach ($ array as $ k =>$ v) {$ a [] = $ data [$ k] ;}$ dataArray [] = $ a ;} Vendor ('zend. classes. PHPExcel '); $ objPHPExcel = new PHPExcel (); $ count = count ($ array); $ count_2 = count ($ dataArray); $ count_2 = $ count_2 + 3; // Set $ objPHPExcel-> setActiveSheetIndex (0)-> setCellValue ('A1', $ filename); $ objPHPExcel-> getActiveSheet ()-> getStyle ('A1') in the first line ') -> getFont ()-> setSize (15); $ objPHPExcel-> getActiveSheet ()-> getStyle ('A1')-> getFont ()-> setBold (true ); $ objPHPExcel-> getActiveSheet ()-> mergeCells ('A1 :'. $ letters_arr [$ count]. '1'); $ objPHPExcel-> getActiveSheet ()-> getStyle ('A1 :'. $ letters_arr [$ count]. '1')-> getAlignment ()-> setHorizontal (PHPExcel_Style_Alignment: HORIZONTAL_CENTER); // load data $ objPHPExcel-> getActiveSheet ()-> fromArray ($ array, NULL, 'A3 '); $ objPHPExcel-> getActiveSheet ()-> fromArray ($ dataArray, NULL, 'A4'); // set the border $ sharedStyle1 = new PHPExcel_Style (); $ sharedStyle1-> applyFromArray (array ('borders' => array ('left' => array ('style' => PHPExcel_Style_Border: BORDER_THIN ), 'right' => array ('style' => PHPExcel_Style_Border: BORDER_THIN), 'top' => array ('style' => PHPExcel_Style_Border: BORDER_THIN ), 'bottom '=> array ('style' => PHPExcel_Style_Border: BORDER_THIN); $ objPHPExcel-> getActiveSheet ()-> setSharedStyle ($ sharedStyle1, 'A3 :'. $ letters_arr [$ count]. $ count_2); // Set the header fill color $ objStyleA3 = $ objPHPExcel-> getActiveSheet ()-> getStyle ('A3 :'. $ letters_arr [$ count]. '3'); $ objStyleA3 = $ objStyleA3-> getFill (); $ objStyleA3-> setFillType (PHPExcel_Style_Fill: FILL_SOLID); $ objStyleA3-> getStartColor () -> setARGB ('ffffbb '); header ('content-Type: application/vnd. ms-excel '); header ('content-Disposition: attachment; filename = "'. $ filename. '"'); header ('cache-Control: max-age = 0'); $ objWriter = PHPExcel_IOFactory: createWriter ($ objPHPExcel, 'excel5 '); $ objWriter-> save ('php: // output'); exit;


Reply to discussion (solution)

1. try not to use getActiveSheet () and change it:
$ ObjSheet = $ objPHPExcel-> getSheet (0 );
$ ObjSheet-> ......
2. if it is still slow, do not use fromArray () to test it. Instead, use a loop cell to insert data.
Hope to help.

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.