Thursday, May 12, 2016

PHPExcel using excel template, increase PHP memory




PHPExcel using excel template:
               $file_path = $_SERVER['DOCUMENT_ROOT'].'/uploads/IAA/IAAtemplate.xlsx';
                $objReader = PHPExcel_IOFactory::createReader('Excel2007');

                $objPHPExcel = $objReader->load($file_path);

        ini_set('zlib.output_compression','Off');
         ob_end_clean();
            header("Pragma: public");
            header("Expires: 0");
            header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
            header("Content-Type: application/force-download");
            header("Content-Type: application/octet-stream");

              header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet; charset=UTF-8');
                $filename = $termFilter."-IAA-".$dept_abbrname."-".date("Ymd").".xlsx";
                header('Content-Disposition: attachment; filename= "'.$filename.'"');
            header("Content-Transfer-Encoding: binary");

        $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
                $objWriter->save('php://output');



This will  take more memory than using without template If you produce  a large
excel file, you may see error: "File not Found" or "Connection reset error".


To fix this: add
         set_time_limit(1000000);
         ini_set("max_input_time", 60000);
         ini_set("memory_limit",-1);

ini_set("memory_limit",-1); will remove PHP  memory limit and will fix memory problem

No comments:

Post a Comment