php - PHPExcel Export for Larger Files fails -


i using phpexcel library generate excel data based on mysql datbase. mysql query results in 1,34,000 rows. , excel supports 65,536 rows on 1 worksheet. made logic

 foreach($result $value) {     $val = array_values($value);      if($rowscounter < 65000)     {         $objphpexcel->addrow($val,$rowscounter);     }     else     {         $active_sheet++;         $objphpexcel->createsheet();         $objphpexcel->setactivesheetindex($active_sheet);         $rowscounter = 1;     }     $rowscounter++; } // deliver header    header("content-type: $mtype; charset=" . $objphpexcel->sencoding); header("content-type:application/octet-stream"); header("content-disposition: inline; filename=\"" . $filename . ".$ext\"");  // save excel 2003 file $objwriter = iofactory::createwriter($objphpexcel,$objphpexcel->sfileformat); //echo "peak memory usage: " . (memory_get_peak_usage(true) / 1024 / 1024) . " mb";exit; $objwriter->save('php://output'); 

to create new worksheet after 65000 records reached 1 woeksheet.

but doesn't work; not giving output or error. thought because of memory limit. when echoed shows peak memory 1400.5 mb , have set memory limit 3500mb using ini_set('memory_limit', '3500m');

could please suggest or alternative?

you might exceeding 65,000 limit, set $rowscounter initial value at? 1 or 0 (zero)? reason ask array results starts @ index 0 (zero), you're adding row , incrementing counter after add. if start counter @ 0 (zero) might have more rows have counted. missing row in else statement, loop through value don't add sheet

try this

$rowscounter = 1;  foreach($result $value) {     $val = array_values($value);      if($rowscounter < 65000)     {         $objphpexcel->addrow($val,$rowscounter);     }     else     {         $active_sheet++;         $objphpexcel->createsheet();         $objphpexcel->setactivesheetindex($active_sheet);         $rowscounter = 1;          // add missing row         $objphpexcel->addrow($val,$rowscounter);     }     $rowscounter++; } // deliver header    header("content-type: $mtype; charset=" . $objphpexcel->sencoding); header("content-type:application/octet-stream"); header("content-disposition: inline; filename=\"" . $filename . ".$ext\"");  // save excel 2003 file $objwriter = iofactory::createwriter($objphpexcel,$objphpexcel->sfileformat); //echo "peak memory usage: " . (memory_get_peak_usage(true) / 1024 / 1024) . " mb";exit; $objwriter->save('php://output'); 

a simple example of i'm trying explain, if $i set 0 (zero) else condition not met. have row in results. if $i set 1 else condition met

$count = array(1,2,3,4,5,6,7,8,9,10); $i=1; // set 0 (zero) , test, set 1 , test  foreach($count $cnt) {     if($i < 10) {         echo "if condition - count value: ".$cnt." value:".$i."<br />";     } else {         echo "else condition - count value: ".$cnt." value:".$i."<br />";     }     $i++; } 

Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -