的Excel與60K +列匯出我有下載在Laravel 4.2如何Laravel
視圖頁面看起來像這樣
ini_set('memory_limit', '-1');
require(app_path().'/libs/excel/Classes/PHPExcel.php');
$objPHPExcel = new PHPExcel();
// Set document properties
$objPHPExcel->getProperties()->setCreator("ideconnect.com")
->setLastModifiedBy("ideconnect.com")
->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");
$arr = array();
$users1 = User::where('event','=',$exceleve)->orderby('name')->with(array('answer'=>function($q) use($qid1){
$q->where('question_id','=','3104')->orWhere('question_id','=','3105');
}))->get();
$user_ids=array();
foreach($users1 as $us){
if($us->answer[0]->answer_text!='' && ($us->role!='admin_dd' || $us->role!='sales_dd')){
$user_ids[] = $us->id;
}
}
$userswithanswers = User::whereIn('id', $user_ids)
->with('answer')
->get();
foreach($userswithanswers as $usa){
$tempansarr = array();
$tempcatansarr = array();
foreach($usa->answer as $ansobj){
$tempansarr[$ansobj->question_id] = $ansobj->answer_text;
}
foreach($usa->categoryvendoranswer as $catansobj){
$tempcatansarr[$catansobj->categoryvendor_id] = $catansobj->answer;
}
$useransarr[$usa->id]['login'] = $usa->email;
$useransarr[$usa->id]['id'] = $usa->id;
$useransarr[$usa->id]['answers'] = $tempansarr;
$useransarr[$usa->id]['catanswers'] = $tempcatansarr;
//dd($tempcatansarr);
}
$questions = Question::orderBy('page')->where('event' ,'=',$exceleve)->where('page' ,'!=',0)->orderBy('order')->get();
//$categoryvendors = Categoryvendor::all();
// HEADER ROW FOR FOR EXCEL
$header1 = array();$header1[]='';
$header2 = array();$header2[]='Login';
$preprojectnumber = '';
foreach($questions as $header){
/*echo $header->class_name."<br>";
echo $header->question_group."<br>";*/
$header3[] = "Page_".$header->page;
if($header->class_name !='projects checkbox group'){
//echo "1";
$header1[] = $header->question_group;
$header2[] = $header->question_text;
} else {
if($header->question_group!=$preprojectnumber){
$header1[] = $header['question_group'];
$header2[] = 'Stage of Buying Cycle';
}
$preprojectnumber = $header->question_group;
}
}
$excelarr = array();
//dd($useransarr);
foreach($useransarr as $usarr){
$b=array();
$b[]=$usarr['login'];
$preprojectnumber = '';
$tempvar = '';
$counter=0;
// dd($usarr['answers']);
foreach($questions as $question){
if($question->class_name!='projects checkbox group'){
$b[] = $usarr['answers'][$question->id];
}
else
{
if($question->question_group!=$preprojectnumber){
$counter=1;
$tempvar = $usarr['answers'][$question->id];
if($usarr['answers'][$question->id]!=''){$tempvar = $tempvar.', ';}
} else {
$tempvar = $tempvar.$usarr['answers'][$question->id];
if($usarr['answers'][$question->id]!=''){$tempvar = $tempvar.', ';}
}
$preprojectnumber = $question->question_group;
$counter++;
if($counter==5){
$b[]=$tempvar;
}
}
}
$excelarr[] = $b;
}
array_unshift($excelarr, $header1);
array_unshift($excelarr, $header2);
$objPHPExcel->setActiveSheetIndex(0)
->fromArray($excelarr, '', 'A1');
$objPHPExcel->getActiveSheet()->setTitle($exceleve);
$styleArray = array(
'font' => array(
'name' => 'Calibri',
'size' => '10',
'color' => array(
'rgb' => 'FFFFFF'
),
'bold' => true,
),
'fill' => array(
'type' => PHPExcel_Style_Fill::FILL_SOLID,
'startcolor' => array(
'rgb' => '000000',
),
),
);
$styleArray2 = array(
'font' => array(
'name' => 'Calibri',
'size' => '10',
'color' => array(
'rgb' => '000000'
),
'bold' => true,
),
'fill' => array(
'type' => PHPExcel_Style_Fill::FILL_SOLID,
'startcolor' => array(
'rgb' => 'cccccc',
),
),
);
$styleArray3 = array(
'font' => array(
'name' => 'Calibri',
'size' => '8',
),
);
$objPHPExcel->setActiveSheetIndex(0)->getDefaultStyle()->applyFromArray($styleArray3);
$objPHPExcel->setActiveSheetIndex(0)->getStyle('A2:LA2')->applyFromArray($styleArray2);
$objPHPExcel->setActiveSheetIndex(0)->getStyle('A1:LA1')->applyFromArray($styleArray);
$objPHPExcel->setActiveSheetIndex(0);
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="event-data.xlsx"');
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
// dd('aaa');
//ob_end_clean();
$objWriter->save('php://output');
exit;
本規範Excel中的一個文件運行非常好,如果行數少,但是,如果數據增加它扔
Memory Limit reach
我只是想知道這把裏面的代碼隊列將解決PROBL他們?
,如果是,那麼我應該怎麼圓點
感謝
可能的重複https://stackoverflow.com/questions/26545538/exporting-large-files-to-excel-using-phpexcel –
@DusanKasan我已經嘗試過它不起作用 – Vikram
我正在使用大的xls和我可以給你的唯一建議是將所有內容寫入CSV,然後將背景隊列從CSV導出到XLS(取決於你擁有的服務器)。它不會讓瀏覽器中大部分數據的工作變得敏感 - 尤其是與XLS一起使用的是巨大的元數據文件格式。 –