Excel导出:浏览器挂断 [英] Excel export: browser hangs up
问题描述
我使用此 http://phpexcel.codeplex.com/导出到excel.
I use this http://phpexcel.codeplex.com/ to export to excel.
需要导出11000-65000行...但尝试执行此操作时,浏览器会挂起.它不会回答错误或其他消息.只是显示正在进行的请求.
need to export 11000 - 65000 rows... but when trying to do this browser hangs up. it do not answer with errors or other messages. just show that request in progress.
top显示apache完成了工作.甚至Apache日志说一切都完成了:
top shows that apache finished work. even apache log says that all done:
x.x.x.x - - [28/Jul/2011:12:28:38 +0300] "POST /doctor/lab/statistic/ HTTP/1.1" 200 2773504 "http://x.x.x.x:82/doctor/lab/statistic/" "Mozilla/5.0 (X11; Linux i686; rv:5.0) Gecko/20100101 Firefox/5.0"
但仍然没有结果.
系统:
Linux Eearth 2.6.34-12-desktop #1 SMP PREEMPT 2010-06-29 02:39:08 +0200 i686
PHP Version 5.3.5
Apache/2.2.15 (Linux/SUSE)
所以这个问题
编辑1
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="'.$filename.'.xls"');
header('Cache-Control: max-age=0');
$writer = PHPExcel_IOFactory::createWriter($xls, 'Excel5');
$writer->save('php://output');
exit;
编辑2
我试图将数据保存到这样的文件中,例如 $ writer-> save('test.xls');
文件大小为2.7MB然后,如果我这样做:
i tried to save data to file like this $writer->save('test.xls');
filesize 2.7MB
then if i do this:
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="'.$filename.'.xls"');
header('Cache-Control: max-age=0');
include 'test.xls';
exit;
下载立即开始...
推荐答案
您的网络服务器可能没有发出错误消息,所以我想检查一下您的error.log(应该挂在/var/log/apache2或类似的文件.)很可能是微不足道的事情,例如无法写入临时文件.
It's possible that your web server is not emitting error messages, so I'd say check your error.log (should be hanging around in /var/log/apache2 or similar.) It might well be something trivial like not being able to write to a temporary file.
如果结果是死胡同,请考虑以编程方式使用echo语句创建CSV文件-Excel将打开这些文件.
If that turns out as a dead-end, consider programmatically creating CSV files with echo statements - Excel will open those just fine.
编辑
要生成CSV,请制作标题
To produce CSV, do your headers
header('Content-Type: text/comma-separated-values);
header('Content-Disposition:attachment;filename="'.$filename.'.csv"');
header('Cache-Control: max-age=0');
然后输出您的列标题:
echo "col1,col2,col3,col4,..."
后跟一个新行.然后输出您的数据:
followed by a new line. Then output your data:
while(/*Still got some rows*/) {
echo $row[0] . "," .$row[1] "," + ...
}
看看: http://en.wikipedia.org/wiki/Comma-separated_values,这是一种非常简单的文件格式,Excel会毫不费力地打开它.
Have a look at: http://en.wikipedia.org/wiki/Comma-separated_values, it's a really simple file format and Excel will open it without difficulty.
我没想到的另一件事是,如果您可以访问Windows Server,则可以直接通过COM interop生成Excel文件.
The other thing, which I hadn't thought of, is if you've got access to a Windows Server, you can produce Excel files directly via COM interop.
这篇关于Excel导出:浏览器挂断的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!