问题描述
与其他许多人一样,我在尝试下载PHPExcel输出的Excel文件时遇到了很多问题.就我而言,发生什么事是什么时候我想使用
Like many others out there i have had my fair share of issues trying to download an Excel file output by PHPExcel.What happened in my case was whenever I wanted to download a file using
$obj->save('php://output')
我总是习惯在excel文件中显示乱码,并警告说我的文件已损坏.最终我解决了这个问题.问题是我有一个
i always used to get garbled text in my excel file with a warning saying my file was corrupt. Eventually i resolved the issue. The problem being i had a
require('dbcon.php')
在我的PHP脚本顶部.我只是用dbcon.php
中的内容替换了它,然后再次正常工作.尽管问题已解决,但我真的很想知道是什么引起了问题.如果外面有人可以帮助我解决这个问题,那就太好了.
at the top of my php script. I just replaced that with whatever was there inside dbcon.php
and it worked fine again.Though the problem is solved i would really like to know what caused the problem. It would be great if anyone out there could help me out with this one.
谢谢.
推荐答案
如果遇到该错误-您应遵循在这种情况下我们始终给出的建议:您使用文本编辑器在生成的文件中查找前导或尾随空格或纯文本错误消息-然后在您自己的脚本中查找可能生成的任何内容,例如echo语句,?>
<?php
外的空行等.
If you get that error - you should follow the advice we always give in that situation: you use a text editor to look in the generated file for leading or trailing whitespace, or plaintext error messages - and then in your own scripts for anything that might generate that such as echo statements, blank lines outside ?>
<?php
, etc.
对此进行测试的另一种方法是保存到文件系统而不是php://output,看看是否遇到相同的问题:如果可行,则问题始终是您自己的脚本发送给php的: //输出.
Another way of testing for this is to save to the filesystem rather than php://output and see if you get the same problem: if that works, then the problem is always something that your own script is sending to php://output as well.
很显然,您在dbcon.php文件中的这些行中都有问题.这可以像在文件中的?>
关闭后尾随换行符一样简单.
Clearly you had a problem along those lines in your dbcon.php file. This can be as simple as a trailing newline after a closing ?>
in the file...
这篇关于PHPExcel输出乱码文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!