請幫我解決將大數據導出爲excel格式xlsx的問題。 我每次導出幾乎45000條記錄到單個文件,並且超時而不保存文件。 mysql選擇查詢需要21秒來執行該大數據。以下是我使用PHP Excel庫將數據導出到Excel文件的代碼。PHPExcel超時發生
$sql2 = "SELECT * FROM Surveys";
$result2 = mysql_query($sql2);
while($row2 = mysql_fetch_assoc($result2))
{
$j=$rowscounter+2;
$sheet->setCellValue("A$j",$row2['brandname']);
$sheet->setCellValue("B$j",$row2['productname']);
$sheet->setCellValue("C$j",$row2['sname']);
$sheet->setCellValue("D$j",$row2['smobile']);
$sheet->setCellValue("E$j",$row2['semail']);
$sheet->setCellValue("F$j",$row2['country']);
$sheet->setCellValue("G$j",$row2['city']);
$sheet->setCellValue("H$j",$row2['sdob']);
$sheet->setCellValue("I$j",$row2['age']);
$sheet->setCellValue("J$j",$row2['comment']);
$sheet->setCellValue("K$j",$row2['outletcode']);
$sheet->setCellValue("L$j",$row2['username']);
$sheet->setCellValue("M$j",$row2['datetime']);
$sheet->setCellValue("N$j",$row2['duration']);
$rowscounter++;
}
// Rename worksheet
$sheet->setTitle('Survey-Report');
$objPHPExcel->setActiveSheetIndex(0);
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->setPreCalculateFormulas(false);
unlink("Survey-Report.xlsx");
$objWriter->save('Survey-Report.xlsx');
echo "ok";
UPDATE:
我忘了提,我已經嘗試過set_timout等,並在我的PHP文件下面的代碼中寫道。
set_time_limit(0);
ini_set('memory_limit','2500M');
php.ini中有一個變量用於爲php腳本執行設置超時值[1]。如果你碰到那可能解決你的問題。 [1]:http://php.net/manual/en/function.set-time-limit.php – 2013-04-26 15:32:55