CakePHP 中的 PHPExcel : error--excel file incompatible or corrupted

标签 php cakephp phpexcel

我正在使用 Cake;当我使用生成函数在浏览器中打开 excel 文件时:

我从 Microsoft Excel 中收到此错误:

Excel cannot open the file 'Groups list .xlsx' because the file format or file extension is not valid. Verify that the file has not been corrupted and that the file extension matches the format of the file.

我试过从浏览器下载文件后去掉文件名中的空格,然后再次打开,它显示了与上述相同的错误。任何人都经历过这个并解决了它?或者有什么线索吗?

基本上 excel 文件已打开,但由于上述错误而为空。我读过一个类似的问题,它说在一个组件文件中删除 ?> 标记末尾的空格。但是我不知道哪个组件文件..?

附言我正在使用 Microsoft Excel 2010,这可能是原因吗? PHPExcel 目前是否适用于“Microsoft Excel 2010”?

最佳答案

PHPExcel Excel2007 Writer 应该生成有效的 xlsx 文件,Excel 2007、Excel 2010 和带有兼容包的 Excel 2003 可以读取这些文件。实际上,我的大部分测试都是使用 Excel2010 和 Excel2003 进行的。

首先要检查的是在文本编辑器中打开文件是否有任何虚假字符被回显到文件中。如果有,那么这些文本可以作为定位问题的指南。尤其要注意文件中作为第一个字符的空格或换行符。

xlsx 文件是 xml 文件的压缩集合,因此如果在文本编辑器中看不到明显的文本字符串(除了 PK 签名),请尝试解压缩它(使用适合您的操作平台的任何解压缩程序)。这可能会给出其他有助于诊断问题的错误消息。

如果您在 Windows 平台上运行,则 ZipArchive 扩展 (php_zip.dll) 的一些错误版本可能会导致此错误。最新的 SVN 代码允许您使用 PCLZip 作为 ZipArchive 的替代品。

如果您仍然遇到问题,请尝试在 PHPExcel 论坛上发帖并提供所有详细信息。

关于CakePHP 中的 PHPExcel : error--excel file incompatible or corrupted,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4942604/

相关文章:

php - 你如何在 Magento 中管理你的扩展版本控制

javascript - CakePHP删除确认

cakephp - 无效的电子邮件 : "from@your_app_domain.com" in cakephp

未检索到 CakePHP 可包含模型

php - 拉维Excel : how to get value of a cell?

php - CodeIgniter session 库 - 潜在危险行为?

javascript - 根据用户的选择禁用在多行上动态生成的文本框

php - 如何在php电子表格图表中设置数据标签的位置

java - 打印 AJAX 成功数据?

excel-formula - 使用phpExcel读取一些单元格