By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,095 Members | 1,658 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,095 IT Pros & Developers. It's quick & easy.

Export data to .csv format in Internet Explorer?

P: 8
Hi all,

I tried to export the data into .csv format.. and the below is how I do it:

container.REQUEST.RESPONSE.setHeader('Content-Type','text/csv')
container.REQUEST.RESPONSE.setHeader('Content-Disposition', 'attachment;filename=outputFile.csv')
container.REQUEST.RESPONSE.write(outputString)

The above works completely fine when I tested it in Firefox, but when I used IE, it will prompt user to save file as a 'Document' file type (& not as expected 'outputFile.csv'). What should I do so that if user uses IE, it will also result in automatic 'outputFile.csv' prompting? Did I set the correct heading (i.e., setHeader)?

On the other hand, I believe that the generated format is still correct, in csv format.

Thanks a lot

Shige
Mar 18 '08 #1
Share this Question
Share on Google+
5 Replies


jlm699
100+
P: 314
I've had this problem before as well. It's an IE problem (as usual), which doesn't handle the setHeaders very well. I don't have a copy of my code that fixes it (I can get it later this evening), however I can point you to this site for some help:

http://downside.ch/blog/?p=26
Mar 18 '08 #2

P: 8
Thanks, jlm699 for your fast reply (as usual)...
:)

For meantime, I will take a look at website you gave.

Shige
Mar 18 '08 #3

P: 8
Visited the website and I tried out the suggestion given, but it didn't help much, still get the same old problem huh..

container.REQUEST.RESPONSE.setHeader('Content-Type','text/csv')
container.REQUEST.RESPONSE.setHeader('Content-Disposition', 'attachment;filename=outputFile.csv')
container.REQUEST.RESPONSE.setHeader('Pragma', 'public')
container.REQUEST.RESPONSE.setHeader('Cache-Control', 'max-age=0')
container.REQUEST.RESPONSE.write(outputString)

Probably I ll wait for Jim to retrieve his code snippet. :) before making much more noise

Thanks
Mar 18 '08 #4

jlm699
100+
P: 314
Alright, went home for lunch and grabbed my old code files... now keep in mind this is PHP but the headers that you need to modify should be the same:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. // Now we'll use header calls to download a file to the client
  4. header('Cache-Control: public, must-revalidate');
  5. header('Pragma: hack');
  6. header('Content-Type: application/vnd.ms-excel');
  7. header('Content-Length: '.(string)(filesize($file_path)));
  8. header('Content-Transfer-Encoding: binary\n');
  9. /*
  10.     Using the "Content-Disposition" header allows us to provide a recommended filename
  11.     as well as force the browser to display the save/open dialog.
  12. */
  13. header('Content-Disposition: attachment; filename="suggestedfilename.csv"');
  14. readfile($file_path);
  15. ?>
  16.  
I don't know why IE is so hard to deal with, but I need all of these headers to get it to display the 'Open/Save' dialog instead of trying to download the .php page itself. Mozilla was fine with the simple way that you did it.

Anyway, I hope that helps... just remember that you'll need to adapt those header calls to your code
Mar 18 '08 #5

P: 8
Jlm,
Thanks for your codes, they are really helpful. :)
Just that I still didn't manage solve the problem, but you already helped much by replying to my questions...
I guess I will keep this problem on the shelf for meantime, & ll come back to look around for the solution again later.

Shige
Mar 19 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.