在 Codeigniter 中使用PHPExcel庫。
大約 20k 行行的小 excel 檔案正在完美生成,而在大檔案(如 43k 行行)的情況下,它得到:
This site can’t be reached
The webpage at
https://exmple.com/
might be temporarily down or it may have moved permanently to a new web address.
ERR_INVALID_RESPONSE
我試過了-
ini_set('max_input_vars', 19999);
set_time_limit ( 6000 );
ini_set('max_execution_time', 6000);
memory_get_usage(true);
但沒有得到結果。
Codeigniter 版本:3.1.11
PHP 版本:7.4
如果需要,部分代碼(不是確切的代碼):
public function test(){
$this->load->library('Excel');
ob_start();
// Create new PHPExcel object
$objPHPExcel = new PHPExcel();
$exlHeading = array(
'font' => array(
'bold' => true,
'size' => 12,
'name' => 'Verdana')
);
// Set document properties
$objPHPExcel->getProperties()->setCreator("BigDream India")
->setLastModifiedBy("TEST")
->setTitle("REPORT")
->setSubject("ATTENDANCE REPORT")
->setDescription("Attendance Monthly Report")
->setKeywords("ATT_REPORT")
->setCategory("Excel Sheet");
for($i=0; $i<=40000; $i ){
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('A'.$i, 'Test content is here.');
$objPHPExcel->setActiveSheetIndex(0)->mergeCells("A$i:I$i");
$objPHPExcel->getActiveSheet()->getStyle("A$i:I$i")->applyFromArray($exlHeading);
}
$objPHPExcel->getActiveSheet()->setTitle('Attendance Monthly Report');
$objPHPExcel->setActiveSheetIndex(0);
ob_end_clean();
$filename = 'MyOfficeGuardian-Monthly_Report.xls';
header('Content-type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="' . $filename . '"');
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('php://output');
}
uj5u.com熱心網友回復:
通過將 php.ini 檔案中的 upload_max_filesize 值從 2mb 更新為 20mb 即可解決問題。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/432435.html
