首页 > 解决方案 > phpspreadsheet 在本地工作但不在现场工作

问题描述

phpspreadsheet我在我的 Codeigniter 项目中安装了 composer 。它在本地运行良好,但在实时环境中引发错误:

无法访问此站点 http://www.xxxxxx.com/email/exportemail上的网页可能暂时关闭,或者它可能已永久移至新网址。ERR_INVALID_RESPONSE

我的代码:

require(APPPATH . 'vendor/autoload.php');

use PhpOffice\PhpSpreadsheet\Helper\Sample;
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Spreadsheet;

class Email extends CI_Controller {

    public function __construct() {
        parent::__construct();
    }
    public function exportemail(){

        $customers = $this->sales_model->getCustomerRows();

        $spreadsheet = new Spreadsheet();
        $spreadsheet->setActiveSheetIndex(0)
                ->setTitle('Location')
                ->setCellValue('A1', 'Customer')
                ->setCellValue('B1', 'Contact name')
                ->setCellValue('C1', 'Managed by')
                ->setCellValue('D1', 'Email');
        foreach($customers as $key => $customers_data) {
            $x = $key + 2;
            $spreadsheet->setActiveSheetIndex(0)
                    ->setCellValue("A$x", $customers_data['cust_pub'])
                    ->setCellValue("B$x", $customers_data['ccd_name'])
                    ->setCellValue("C$x", $customers_data['m_name'])
                    ->setCellValue("D$x", $customers_data['cust_pub_email']);
        }
        $filename = 'Export_Email.xlsx'; //save our workbook as this file name
        // Redirect output to a client’s web browser (Xlsx)
        header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
        header('Content-Disposition: attachment;filename="'.$filename.'"');
        header('Cache-Control: max-age=0');
        // If you're serving to IE 9, then the following may be needed
        header('Cache-Control: max-age=1');

        // If you're serving to IE over SSL, then the following may be needed
        header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
        header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); // always modified
        header('Cache-Control: cache, must-revalidate'); // HTTP/1.1
        header('Pragma: public'); // HTTP/1.0

        $writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
        $writer->save('php://output');
    }
}

谁能告诉我现场需要做哪些改变?

标签: codeigniterphpspreadsheet

解决方案


推荐阅读