46817

Excel export: browser hangs up

Question:

I use this <a href="http://phpexcel.codeplex.com/" rel="nofollow">http://phpexcel.codeplex.com/</a> 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

<strong>EDIT 1</strong>

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;

<strong>EDIT 2</strong>

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

Answer1:

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.

<strong>EDIT</strong>

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: <a href="http://en.wikipedia.org/wiki/Comma-separated_values" rel="nofollow">http://en.wikipedia.org/wiki/Comma-separated_values</a>, 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.

Recommend

  • old vs new version of Z3
  • Delete data from mysql and angular
  • Qt QComboBox popup position
  • Can I apply the Git-Flow workflow on GitHub
  • if(!isset($_POST[“user”]) ignored and returns Undefined Index
  • Laravel at least one field is required
  • File extension of zlib zipped html page?
  • iOS Cordova first plugin - plugin.xml to inject a feature
  • configure: error: no acceptable C compiler found in $PATH
  • How to view images from protected folder with php?
  • App restarts from wrong activity
  • How to convert workspace coordinates to screen coordinates?
  • How to add git credentials to the build so it would be able to be used within a shell code?
  • How to define custom class, title, and target in Link Browser for content elements and the new rte_c
  • Textfile Structure (tables)
  • Installing iPhone App to iPhone
  • Problem deserializing objects from cache on MyBatis 3/Java
  • MVC3 Razor - ListBox pre-select not working
  • Could not find rake using whenever rails
  • How to install a .deb file on a jailbroken iphone programmatically?
  • Cannot resolve symbol 'MyApi'
  • How to delay loading a property with linq to sql external mapping?
  • Recording logins for password protected directories
  • SignalR .NET Client Invoke throws an exception
  • Lost migrations and Azure database is now out of sync
  • Cannot connect to cassandra from Spark
  • Java Scanner input dilemma. Automatically inputs without allowing user to type
  • How do I fake an specific browser client when using Java's Net library?
  • Sony Xperia Z Tablet not found by adb
  • How to get a value (ex: baseURL) in every Karate feature?
  • Validaiting emails with Net.Mail MailAddress
  • Deserializing XML into class C#
  • vba code to select only visible cells in specific column except heading
  • Timeout for blocking function call, i.e., how to stop waiting for user input after X seconds?
  • Windows forms listbox.selecteditem displaying “System.Data.DataRowView” instead of actual value
  • How to include full .NET prerequisite for Wix Burn installer
  • Proper folder structure for lots of source files
  • How does Linux kernel interrupt the application?
  • costura.fody for a dll that references another dll
  • jQuery Masonry / Isotope and fluid images: Momentary overlap on window resize