Php 如何通过codeigniter导出和下载excel文件,excel文件未创建(下载)
headerCache控制:无存储,无缓存,必须重新验证 头痛控制:后检查=0,前检查=0,假 HeaderFragma:无缓存 标题“Content-Type:application/vnd.openxmlformats officedocument.spreadsheetml.sheet” 标题的内容处理:附件;filename=subscribers_sheet.csv'Php 如何通过codeigniter导出和下载excel文件,excel文件未创建(下载),php,codeigniter,Php,Codeigniter,headerCache控制:无存储,无缓存,必须重新验证 头痛控制:后检查=0,前检查=0,假 HeaderFragma:无缓存 标题“Content-Type:application/vnd.openxmlformats officedocument.spreadsheetml.sheet” 标题的内容处理:附件;filename=subscribers_sheet.csv' $objWriter->savephp://output; 日志中有错误吗?请在您的答案中添加一些上下文,并解释它如何
$objWriter->savephp://output; 日志中有错误吗?请在您的答案中添加一些上下文,并解释它如何解决OP的问题。就目前的情况而言,几行没有解释的代码并不是特别有用。
//query fetching data from database
if (!$query)
return false; //if there is no data in query return false
// Starting the PHPExcel library
$this->load->library('PHPExcel');//loading library
$objPHPExcel = new PHPExcel();
$objPHPExcel->getProperties()->setTitle("export")->setDescription("none");
$objPHPExcel->setActiveSheetIndex(0);
// Field names in the first row
$fields = $query->list_fields();
$col = 0;
//add data into cells
foreach ($fields as $field) {
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, 1, $field);
$col++;
}
// Fetching the table data
$row = 2;
foreach ($query->result() as $data) {
$col = 0;
foreach ($fields as $field) {
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $data->$field);
$col++;
}
$row++;
}
$objPHPExcel->setActiveSheetIndex(0);
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'csv');
//creating excel sheet
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="subscribers_sheet.csv"');
header('Cache-Control: max-age=0');
header('Cache-Control: max-age=1');
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
$objWriter->save('php://output');// inserting data into excel sheet