我正在使用excel库来创建和下载excel文件。
$name="ABC #TEST";
$this->excel->setActiveSheetIndex(0);
$this->excel->stream($name.'.xls', $data);
当我从名称中删除#时,它会下载excel文件。否则,它会将我重定向到错误页面。
请帮忙,谢谢。
答案 0 :(得分:1)
如果要使用#(哈希)下载它,请尝试一下。
$filename='ABC #TEST.xls'; //save our workbook as this file name
header('Content-Type: application/vnd.ms-excel'); //mime type
header('Content-Disposition: attachment;filename="'.$filename.'"'); //tell browser what's the file name
header('Cache-Control: max-age=0'); //no cache
//save it to Excel5 format (excel 2003 .XLS file), change this to 'Excel2007' (and adjust the filename extension, also the header mime type)
//if you want to save it as .XLSX Excel 2007 format
$objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'Excel5');
//force user to download the Excel file without writing it to server's HD
$objWriter->save('php://output');
希望有帮助。