【发布时间】:2019-06-04 23:59:29
【问题描述】:
当我单击导出按钮时,它会转到我的export_inquiry() 函数,我已经设置了来自 DB 表的数组,并使用此动态数组数据下载了 excel 文件。但是,现在它给我带来了错误
无法访问此站点
http://www.example.com/project_name/admin/order/export_inquiry 的网页可能暂时关闭,或者它可能已永久移动到新网址。
ERR_INVALID_RESPONSE。
我正在使用CodeIgniter 中的PHPExcel 库来下载excel 文件。下面是我的excel导出代码。
public function export_inquiry()
{
ini_set('display_startup_errors',1);
ini_set('display_errors',1);
error_reporting(E_ALL);
$this->load->library('phpexcel/PHPExcel');
$object = new PHPExcel();
$object->setActiveSheetIndex(0);
$table_columns = array("DATE", "ID", "CustomerReference", "InvoiceName", "PickUpCity", "PickUpDate");
$column = 0;
foreach($table_columns as $field)
{
$object->getActiveSheet()->setCellValueByColumnAndRow($column, 1, $field);
$column++;
}
$employee_data =array(
array(
'order_date' => '2018-05-23 22:35:36',
'id' => 17,
'customerreference' => '',
'invoice_name' => 'Troy Design and Manufacturing',
'pick_up_city' => 'Gothenburg',
'pick_up_date' => '2018-07-02'
),
array(
'order_date' => '2018-05-28 02:51:58',
'id' => 19,
'customerreference' => '',
'invoice_name' => 'Hollingsworth Distribution Systems',
'pick_up_city' => 'Gothenburg',
'pick_up_date' => '2018-07-02'
),
array(
'order_date' => '2018-05-28 04:39:23',
'id' => 20,
'customerreference' => '',
'invoice_name' => 'Motherson Automotive (FSP-1)',
'pick_up_city' => 'Gothenburg',
'pick_up_date' => '2018-07-02'
)
);
$excel_row = 2;
foreach($employee_data as $key => $row)
{
$object->getActiveSheet()->setCellValueByColumnAndRow(0, $excel_row, $row['order_date']);
$object->getActiveSheet()->setCellValueByColumnAndRow(1, $excel_row, $row['id']);
$object->getActiveSheet()->setCellValueByColumnAndRow(2, $excel_row, $row['customerreference']);
$object->getActiveSheet()->setCellValueByColumnAndRow(3, $excel_row, $row['invoice_name']);
$object->getActiveSheet()->setCellValueByColumnAndRow(4, $excel_row, $row['pick_up_city']);
$object->getActiveSheet()->setCellValueByColumnAndRow(5, $excel_row, $row['pick_up_date']);
$excel_row++;
}
$object_writer = PHPExcel_IOFactory::createWriter($object, 'Excel5');
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="Employee Data.xls"');
$object_writer->save('php://output');
}
谁能帮我解决这个问题? 提前致谢。
【问题讨论】:
标签: php excel codeigniter download phpexcel