About the Phpexcel output report when there are tens of thousands of records, it seems to hang up?

Source: Internet
Author: User
This is a fully available Phpexcel example

Getactivesheet ()->freezepane (' A2 '); $sharedStyle 1 = new Phpexcel_style (); $sharedStyle 1->applyfromarray (array (' fill ' = = Array (' type ' = = phpexcel_style_fill::fill_solid, ' color ' = = Array (' ARGB ' = ' FFCCFFCC '), ' borders ' = = Array (' bottom ' = = Array (' style ' = = Phpexcel_                Style_border::border_thin), ' right ' = = Array (' style ' = Phpexcel_style_border::border_medium)                )); $sharedStyle 2 = new Phpexcel_style (); $sharedStyle 2->applyfromarray (Array (' fill ' = = Array (            ' Type ' = phpexcel_style_fill::fill_solid, ' color ' = = Array (' ARGB ' = ' fff4f4f4 ')   )); $objPHPExcel->getactivesheet ()->setsharedstyle ($sharedStyle 1, "A1:o1"); $objPHPExcel->getactivesheet ()->getcolumndimension (' A ')->setwidth ($objPHPExcel->getactivesheet ()->getcolumndimension (' B ')->setwidth (a); $objPHPExcel-> Getactivesheet ()->getcolumndimension (' C ')->setwidth (), $objPHPExcel->getactivesheet () Getcolumndimension (' D ')->setwidth (), $objPHPExcel->getactivesheet ()->getcolumndimension (' E ') SetWidth, $objPHPExcel->getactivesheet ()->getcolumndimension (' F ')->setwidth ($objPHPExcel) Getactivesheet ()->getcolumndimension (' G ')->setwidth, $objPHPExcel->getactivesheet () Getcolumndimension (' H ')->setwidth (), $objPHPExcel->getactivesheet ()->getcolumndimension (' I ') SetWidth, $objPHPExcel->getactivesheet ()->getcolumndimension (' J ')->setwidth ($objPHPExcel) Getactivesheet ()->getcolumndimension (' K ')->setwidth (), $objPHPExcel->getactivesheet () Getcolumndimension (' L ')->setwidth (), $objPHPExcel->getactivesheet ()->getcolumndimension (' M ') SetWidth, $objPHPExcel->getactivesheet ()->getcolumndimension (' N ')->setwidth ($objPHPExcel) Getactivesheet ()->getcolumndimension (' O ')->seTwidth (), $objPHPExcel->getactivesheet ()->settitle (' Student Export ');//The name of the former worksheet? for ($i =0;$ Igetactivesheet ()->getstylebycolumnandrow ($i, 1)->getfont ()->setbold (TRUE);//Place the first line? Bold} $objPHPExcel- >getactivesheet ()->setcellvaluebycolumnandrow (0, 1, ' first Name '); $objPHPExcel->getactivesheet () Setcellvaluebycolumnandrow (1, 1, ' last Name '); $objPHPExcel->getactivesheet ()->setcellvaluebycolumnandrow (2, 1, ' Date of Birth '); $objPHPExcel->getactivesheet ()->setcellvaluebycolumnandrow (3, 1, ' attendance Year '); $ Objphpexcel->getactivesheet ()->setcellvaluebycolumnandrow (4, 1, ' Course studied '); $objPHPExcel Getactivesheet ()->setcellvaluebycolumnandrow (5, 1, ' Agency booking/direct Booking '); $objPHPExcel Getactivesheet ()->setcellvaluebycolumnandrow (6, 1, ' Student country '); $objPHPExcel->getactivesheet () Setcellvaluebycolumnandrow (7, 1, ' Student City '); $objPHPExcel->getactivesheet ()->setcellvaluebycolumnandrow (8, 1, ' Student Home phone NumbeR '); $objPHPExcel->getactivesheet ()->setcellvaluebycolumnandrow (9, 1, ' Student Mobile phone number '); $ Objphpexcel->getactivesheet ()->setcellvaluebycolumnandrow (1, ' Student Email address '), $objPHPExcel Getactivesheet ()->setcellvaluebycolumnandrow (one, 1, ' Emergency contact Name '); $objPHPExcel->getactivesheet () ->setcellvaluebycolumnandrow (1, ' Emergency Contact phone number 1 '); $objPHPExcel->getactivesheet () Setcellvaluebycolumnandrow (1, ' Emergency Contact phone number 2 '); $objPHPExcel->getactivesheet () Setcellvaluebycolumnandrow (1, ' Order Date '), $number =1; $orderdate = "; $firstname ="; $lastname = "; $dateodbirth = ' '; $attenddance = '; $studied = '; $booking = '; $country = '; $city = '; $home _phone= '; $mobile _phone= '; $email = '; $emer _name= '; $emer _phone1= '; $emer _phone2= "; $sql =" Select orders_id,date_purchased from Orders order by orders_id DESC "; $ Query=mysql_query ($sql), while ($arr =mysql_fetch_array ($query)) {$number + +; $orderdate = $arr [' date_purchased '];$ Sql2= "SELECT * from Orders_extra_info where orders_id= '". $arr [' orders_id ']. "'"; $query 2=mysql_query ($sql 2), $num 2=mysql_num_rows ($query 2), if ($num 2>0) {$arr 2=mysql_fetch_array ($query 2); Firstname= $arr 2[' first_name '); $lastname = $arr 2[' last_name ']; $dateodbirth = $arr 2[' Date_of_birth ']; $attenddance =$ arr2[' o_attendaceyear '; $booking = $arr 2[' o_agency '];if ($booking ==1) {$booking = ' Direct Sale ';} if ($booking ==2) {$booking = ' Agent Sale ';} $country _id= $arr 2[' country ']; $city = $arr 2[' city '; $home _phone= $arr 2[' phone1 ']; $mobile _phone= $arr 2[' Phone2 '];$ email= $arr 2[' email '; $emer _name= $arr 2[' emc_name ']; $emer _phone1= $arr 2[' emc_phone1 ']; $emer _phone2= $arr 2[' emc_ Phone2 ']; $cou _sql= "Select Countries_id,countries_name from countries where countries_id= '". $country _id. "'"; $con _query=mysql_query ($cou _sql), $con _arr=mysql_fetch_array ($con _query); $country = $con _arr[' countries_name '];} $sql 3= "Select products_name,orders_id from orders_products where orders_id= '". $arr [' orders_id ']. "'"; $query 3=mysql_query ($sql 3); $num 3=mysql_num_rows ($Query3), if ($num 3>0) {$studied = ", while ($arr 3=mysql_fetch_array ($query 3)) {$studied. = $arr 3[' products_name '].", ";} $studied =substr ($studied, 0,strlen ($studied)-1);} $objPHPExcel->getactivesheet ()->setcellvaluebycolumnandrow (0, $number, $firstname); $objPHPExcel Getactivesheet ()->setcellvaluebycolumnandrow (1, $number, $lastname); $objPHPExcel->getactivesheet () Setcellvaluebycolumnandrow (2, $number, $dateodbirth); $objPHPExcel->getactivesheet () Setcellvaluebycolumnandrow (3, $number, $attenddance); $objPHPExcel->getactivesheet () Setcellvaluebycolumnandrow (4, $number, $studied); $objPHPExcel->getactivesheet () Setcellvaluebycolumnandrow (5, $number, $booking); $objPHPExcel->getactivesheet () Setcellvaluebycolumnandrow (6, $number, $country); $objPHPExcel->getactivesheet () Setcellvaluebycolumnandrow (7, $number, $city); $objPHPExcel->getactivesheet ()->setcellvaluebycolumnandrow (8 , $number, $home _phone); $objPHPExcel->getactivesheet ()->setcellvaluebycoLumnandrow (9, $number, $mobile _phone), $objPHPExcel->getactivesheet ()->setcellvaluebycolumnandrow (10, $ number, $email); $objPHPExcel->getactivesheet ()->setcellvaluebycolumnandrow (one, $number, $emer _name); $ Objphpexcel->getactivesheet ()->setcellvaluebycolumnandrow ($number, $emer _phone1), $objPHPExcel Getactivesheet ()->setcellvaluebycolumnandrow ($number, $emer _phone2); $objPHPExcel->getactivesheet ()- >setcellvaluebycolumnandrow ($number, $orderdate);} $objPHPExcel->setactivesheetindex (0);//? What's that? worksheet $excelname = ' Student_export '. Date ("Ymdhis"). XLS ';//? out of Excel filename $objwriter = phpexcel_iofactory::createwriter ($objPHPExcel, ' Excel5 '); Header ("Content-type: Application/force-download "); Header (" Content-type:application/octet-stream "); Header (" content-type:application/ Download "); header (" Content-disposition:attachment; Filename= ". UrlEncode ($excelName)); Header (" Content-transfer-encoding:binary "); Header (" Expires:mon, Jul 1997 05:00:00 GMT "); Header ("Last-modified: ". Gmdate ("D, D M Y h:i:s"). "GMT"), Header ("Cache-control:must-revalidate, Post-check=0, pre-check=0"), Header ("Pragma:no-cache"); $objWriter- >save (' php://output '); require (dir_ws_includes. ' application_bottom.php ');? >

output to the report, when there are tens of thousands of records, can not be exported, the browser has been re-rotating, only small amount of data when it is useful, how to do?

Reply to discussion (solution)

There are several ways to use the cache:
1). Phpexcel_cachedobjectstoragefactory::cache_in_memory;
By default, if you do not initialize any of the caching methods, Phpexcel will use the way the memory is cached.
2). phpexcel_cachedobjectstoragefactory::cache_in_memory_serialized;
Using this caching method, cells are stored in memory in a serialized manner, which is a scenario that reduces memory utilization performance.
3). Phpexcel_cachedobjectstoragefactory::cache_in_memory_gzip;
Similar to serialization, this method, after serialization, is then gzip compressed and then put into memory, which further reduces the use of memory, but there are some slow reads and writes.
4). Phpexcel_cachedobjectstoragefactory::cache_to_discisam;
When using Cache_to_discisam this way, all cells will be saved in a temporary disk file, only their location in the file in PHP memory, which is slower than any kind of cache in memory, but can significantly reduce the use of memory. Temporary disk files are automatically deleted at the end of the script run.
5). Phpexcel_cachedobjectstoragefactory::cache_to_phptemp;
Similar to Cache_to_discisam, when using cache_to_phptemp, all cells are still present in the php://temp I/O stream, and only their location is stored in PHP memory. PHP's Php://memory wrapper stores the data in memory, Php://temp behaves similarly, but when the stored data size exceeds the memory limit, the data is saved in a temporary file, the default size is 1MB, but you can modify it at initialization time: You should export up to 20,000 values. There are several ways to use the cache:

1). Phpexcel_cachedobjectstoragefactory::cache_in_memory;

By default, if you do not initialize any of the caching methods, Phpexcel will use the way the memory is cached.
2). Phpexcel_cachedobjectstoragefactory::cache_in_memory_seria ...
Memory issues, Tagging ~

Add
Phpexcel says Phpexcel uses memory for each cell size of 1K

What is said to be imported in batches? Is there an example of how to write

Just check it out on the Internet.

No such demand, who will go to test?

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