Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/268.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHPExcel……电子表格显示在网页上,而不是下载_Php_Phpexcel - Fatal编程技术网

PHPExcel……电子表格显示在网页上,而不是下载

PHPExcel……电子表格显示在网页上,而不是下载,php,phpexcel,Php,Phpexcel,您可以尝试添加这两个标题,但我不确定它是否有用(我没有测试它): 除了指出的内容外,您还可以尝试将以下内容添加到标题中: header("Content-Description: File Transfer"); header("Content-Transfer-Encoding: Binary"); 即使提示下载文件时似乎不需要它们(我尝试的示例中的代码行与您的代码行相同,并且它在IE 10和Chrome中下载时没有问题)Php代码 header("Content-Type: applica

您可以尝试添加这两个标题,但我不确定它是否有用(我没有测试它):


除了指出的内容外,您还可以尝试将以下内容添加到标题中:

header("Content-Description: File Transfer");
header("Content-Transfer-Encoding: Binary");
即使提示下载文件时似乎不需要它们(我尝试的示例中的代码行与您的代码行相同,并且它在IE 10和Chrome中下载时没有问题)

Php代码

header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
标题(“Pragma:public”);
标题(“到期日:0”);
标头(“缓存控制:必须重新验证,后检查=0,前检查=0”);
标题(“内容类型:应用程序/强制下载”);
标题(“内容类型:应用程序/八位字节流”);
标题(“内容类型:应用程序/下载”);
标题(“内容处置:附件;文件名=export.xls”);
标题(“内容传输编码:二进制”);
回音条标签($_POST['tableData'],'');
然后使用下面的javascript导出

 header("Pragma: public");
 header("Expires: 0");
 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
 header("Content-Type: application/force-download");
 header("Content-Type: application/octet-stream");
 header("Content-Type: application/download");
 header("Content-Disposition: attachment;filename=export.xls");
 header("Content-Transfer-Encoding: binary ");

echo strip_tags($_POST['tableData'],'<table><th><tr><td>');
$(函数()
{
$(“#exportToExcel”)。单击
(功能()
{
var data=''+$(“#ReportTable”).html().替换(/]+>/gi,'')+'';
$('body')。前缀(“”);
$('#ReportTableData').submit().remove();
返回false;
d}
);
}
);

您是否尝试使用不同的浏览器?我的Chrome通常会下载所有文件,而FireFox只会在选项卡中显示pdf文档,虽然我没有注意到excel文件也有同样的问题,但我已经在Chrome、FireFox和Internet explorer上尝试过,但仍然会显示在网页上。你解决过这个问题吗?Mjukis…..见下面我的答案
 header("Pragma: public");
 header("Expires: 0");
 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
 header("Content-Type: application/force-download");
 header("Content-Type: application/octet-stream");
 header("Content-Type: application/download");
 header("Content-Disposition: attachment;filename=export.xls");
 header("Content-Transfer-Encoding: binary ");

echo strip_tags($_POST['tableData'],'<table><th><tr><td>');
 $(function()      
        {
      $("#exportToExcel").click
         (function()                                   
          {
          var data='<table>'+$("#ReportTable").html().replace(/<a\/?[^>]+>/gi, '')+'</table>';
        $('body').prepend("<form method='post' action='php/exporttoexcel.php' style='display:none' id='ReportTableData'><input type='text' name='tableData' value='"+data+"' ></form>");
        $('#ReportTableData').submit().remove();
        return false;
       d}
      );
       }
     );