codeigniter - 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');
}
}
谁能告诉我现场需要做哪些改变?
解决方案
推荐阅读
- ionic-framework - Ionic 4 ion-item 内的多个可点击项目(例如无线电项目或复选框)
- ansible - 如何在ansible中使用when条件和循环将库存列表元素与vars yml列表匹配
- c# - 如何将行插入到 SQL 数据库的表中?
- mysql - mysql 在我使用刚刚插入的值选择另一个表后什么也不返回
- excel - 选择下拉列表时填写数据
- hadoop - 如何使用即席查询提高 Hive 的性能
- r - 如何停止 ggplotly() 以意想不到的方式更改刻面图的侧标签的位置?
- javascript - bootstrap 4 carousel - 图像指示器显示/隐藏
- pandas - 数据框熊猫中的列值替换
- validation - 如何解决使用 Cerberus 验证 3 层 YAML 文件的问题?