我想在excel下载报告我有以下代码 [英] I want to download report in excel I have following code
本文介绍了我想在excel下载报告我有以下代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
$filename='Rake Report '.$rail_head.'.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');
但是它给出了错误As:Excel无法打开文件,因为文件格式和扩展名无效。
我尝试过:
i试图将文件打开到Apache OpenOffice和LibreOffice中,但仍有相同的问题。任何帮助都应该感谢提前感谢。
But it gives error As: Excel cannot open the file because the file format and extension is not valid.
What I have tried:
i have tried to open the file into Apache OpenOffice and in LibreOffice also but there remain the same issue.Any help wold be appreciated Thanks in Advance.
推荐答案
filename ='Rake Report'。
filename='Rake Report '.
rail_head。'。xls'; //将我们的工作簿保存为此文件名
header('Content-Type:application / vnd.ms-excel'); // mime type
header('Content-Disposition:attachment; filename ='。
rail_head.'.xls'; //save our workbook as this file name header('Content-Type: application/vnd.ms-excel'); //mime type header('Content-Disposition: attachment;filename="'.
filename。''); //告诉浏览器文件名是什么
header('Cache-Control:max-age = 0'); //没有缓存
//将其保存为Excel5格式(excel 2003 .XLS文件),将其更改为Excel2007(并调整文件扩展名,也就是标题mime类型)
//如果要将其另存为.XLSX Excel 2007格式
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
这篇关于我想在excel下载报告我有以下代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文