Monday, March 19, 2007

IE7 does not Excel

The statistical module on one of our web applications has a function to download the data directly into Microsoft Excel. This function has been working like a charm since the application was deployed last year, but now we got problem reports from IE7 users that were unable to use the function.

I did a quick test and found no problem, a not so uncommon situation for anyone involved in software development. I thought about reporting the usual "It works in development" back to the customer when I figured I should do another test using the full test environment. I now got the reported failure; IE7 fails to download the file and a popup is shown instead. Aha! Its HTTPS that's causing this.

After some digging around I found the answer in the header() documentation on php.net. To get file downloads to work for IE7 you must add two more headers to the response:


header('Pragma: private');
header('Cache-control: private, must-revalidate');

This will tell IE7 to allow the encrypted file to be saved locally, a requirement to be able to open the file using Excel. I have not found any pointers about why the functionality was changed between IE6 and IE7.

I hope this saves an hour for you!

3 comments:

Anonymous said...

Thanks for that, you fixed something that took me a hour searching for the fix on, with no avail.

Anonymous said...

This rocks, I spent almost two hours for the IE7/Excel problem. This solved in an instant. Thanks and keep posting. This should have been first page in google search.

Unknown said...

Thanks for the fix.