codeigniter 未生成大型Excel文件,出现错误:错误_无效_响应

9fkzdhlc  于 2022-12-07  发布在  其他
关注(0)|答案(1)|浏览(86)

在Codeigniter中使用PHPExcel库。
约20 k行的小excel文件生成完美,而在大(如43 k行)文件的情况下,它得到:

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);

但没有结果。
代码点火器版本: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');
}
jqjz2hbq

jqjz2hbq1#

通过在php.ini文件中将upload_max_filesize值从2mb更新为20mb解决了问题。

相关问题