0
votes

I use this http://phpexcel.codeplex.com/ to export to excel.

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 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"

but still no results.

system:

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) 

so the question

EDIT 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;

EDIT 2

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;

download starts immediate...

1
Try removing the exit; command - Trefex
@Trefex this code is a part of framework. if i remove exit - many other data will attached and i don`t think this is solution - Subdigger

1 Answers

1
votes

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.

If that turns out as a dead-end, consider programmatically creating CSV files with echo statements - Excel will open those just fine.

EDIT

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');

Then output your column headers:

echo "col1,col2,col3,col4,..." 

followed by a new line. Then output your data:

while(/*Still got some rows*/) {
   echo $row[0] . "," .$row[1] "," + ...
}

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.

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.