Large excel file is not generating, getting error: ERR_INVALID_RESPONSE
Large excel file is not generating, getting error: ERR_INVALID_RESPONSE
在 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 Version: 3.1.11
PHP Version: 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');
}
只需将 php.ini 文件中的 upload_max_filesize 值从 2mb 更新为 20mb 即可解决问题。
在 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 Version: 3.1.11
PHP Version: 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');
}
只需将 php.ini 文件中的 upload_max_filesize 值从 2mb 更新为 20mb 即可解决问题。