3

I tried to write data into excel with a million record using phpExcel. but it take too much time.

 

    $header=array('test1','test1','test1','test1','test1','test1','test1','test1');
    
$objPHPExcel = new PHPExcel();
// Set document properties
$objPHPExcel->getProperties()->setCreator("Maarten Balliauw") ->setLastModifiedBy("Maarten Balliauw") ->setTitle("Office 2007 XLSX Test Document") ->setSubject("Office 2007 XLSX Test Document") ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.") ->setKeywords("office 2007 openxml php") ->setCategory("Test result file");
$objPHPExcel->getActiveSheet()->fromArray($header,NULL,'A1');
$sheet = $objPHPExcel->getActiveSheet();
// $final_xls_data1 is set of small records // $rowcount this variable is set of old rowcounts and set
$rowcount=$rowcount +1.
// create 8 small set of records. then add array in excel object $sheet->fromArray($final_xls_data1,NULL,'A'.$rowcount); $objPHPExcel->getActiveSheet()->setTitle('Simple'); $objPHPExcel->setActiveSheetIndex(0); header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); header('Content-Disposition: attachment;filename="01simple.xlsx"'); header('Cache-Control: max-age=0'); header('Cache-Control: max-age=1'); header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1 header ('Pragma: public'); // HTTP/1.0 $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); $objWriter->save($xls_file_path);

How can I do this?

pnuts
  • 58,317
  • 11
  • 87
  • 139
pmali
  • 67
  • 1
  • 6
  • 3
    This is not a page to give you solutions but a page to give you help. Show us your sourcecode and what you have tried so far. – Tom K. Sep 07 '15 at 14:59
  • Have you read ___any___ of the existing answers here, or threads on the PHPExcel site, about how to improve performance? If so, what methods have you tried to use? – Mark Baker Sep 07 '15 at 16:14
  • HI mark, i have uploaded code please look in code let me konw if any left in code for performance – pmali Sep 09 '15 at 10:15
  • If I set 10 lac at a time then it will go in infinite loop. that's why I create 8 small set. but then it will take same time – pmali Sep 09 '15 at 14:29

1 Answers1

1

If you are using PHPExcel, look at this: https://stackoverflow.com/a/5984286/4499987. Mark talks about a bunch of ways to optimize PHPExcel. There are a lot of other posts that you can find help from.

If you really care about speed, I'd also recommend you to take a look at Spout: https://github.com/box/spout. It is super simple to use, does not require any optimizations and should help you create your Excel file in no time!

Community
  • 1
  • 1
Adrien
  • 1,929
  • 1
  • 13
  • 23