Excel导出PHP问题 [英] Excel Exporting in PHP issues

查看:189
本文介绍了Excel导出PHP问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个问题,我有一个简单的PHP文件,将一个表导出到扩展名为.xls的excel文件。导出的代码如下所示:

Here is the issue I have a simple PHP file that exports a table to an excel file with the extension ".xls". The code that makes the export goes like this:

header ("Last-Modified: " . gmdate("D,d M YH:i:s") . " GMT");
header ("Cache-Control: no-cache, must-revalidate");
header ("Content-type: application/x-msexcel");
header ("Content-Disposition: attachment; filename=filename.xls" );
header("Content-Description: PHP/INTERBASE Generated Data" );
header("Expires: 0");
Rest of the PHP code that has HTML tags for the table

这个PHP类被称为从一个这样的buton:

This PHP class is called from a buton that goes like this:

<input type="submit" name="button2" onclick = "this.form.action = 'ExcelExportFile.php'" value='Export to Excel'>

浏览器提示文件要下载或保存。
根据用户计算机中安装的Excel版本,尝试打开下载的文件时,会出现此问题:

The browser prompts for the file to either be downloaded or saved. The issue starts when trying to open the downloaded file depending on which Excel version is installed in the user's computer:


  • Excel 2010 ,Excel 2013:所有它是打开Excel而不打开文件,该程序没有提供任何提示或任何警告,它只是挂在一个灰色的窗口。

  • Excel 2016打开文件不会在用户说该文件可能已损坏,并询问用户是否确定打开该文件。单击是,文件正确打开显示表

我已尝试从Microsoft的网页排除故障,但没有任何作用。关于这里的有趣的部分是,如果你去文件 - >打开 - >最近的书籍并点击下载的文件,现在它打开正确,没有对文件进行任何更改。

I have tried the troubleshoot from Microsoft's web page but nothing works. The interesting part about here is that if you go File -> Open -> Recent Books and click on the downloaded file, now it opens up correctly without making any changes on the file whatsoever.

推荐答案

微软最近发布了几个更新,阻止它打开包含HTML的excel文件。 KB 3115322,3115262安全更新

Microsoft have issued a couple of updates recently that stop it opening excel files that contain HTML. KB 3115322, 3115262 security updates

这篇关于Excel导出PHP问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆