Export data to .csv format in Internet Explorer?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shigehiro
    New Member
    • Oct 2006
    • 8

    Export data to .csv format in Internet Explorer?

    Hi all,

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

    container.REQUE ST.RESPONSE.set Header('Content-Type','text/csv')
    container.REQUE ST.RESPONSE.set Header('Content-Disposition', 'attachment;fil ename=outputFil e.csv')
    container.REQUE ST.RESPONSE.wri te(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
  • jlm699
    Contributor
    • Jul 2007
    • 314

    #2
    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:

    Comment

    • shigehiro
      New Member
      • Oct 2006
      • 8

      #3
      Thanks, jlm699 for your fast reply (as usual)...
      :)

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

      Shige

      Comment

      • shigehiro
        New Member
        • Oct 2006
        • 8

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

        container.REQUE ST.RESPONSE.set Header('Content-Type','text/csv')
        container.REQUE ST.RESPONSE.set Header('Content-Disposition', 'attachment;fil ename=outputFil e.csv')
        container.REQUE ST.RESPONSE.set Header('Pragma' , 'public')
        container.REQUE ST.RESPONSE.set Header('Cache-Control', 'max-age=0')
        container.REQUE ST.RESPONSE.wri te(outputString )

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

        Thanks

        Comment

        • jlm699
          Contributor
          • Jul 2007
          • 314

          #5
          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:
          [code=php]
          <?php

          // Now we'll use header calls to download a file to the client
          header('Cache-Control: public, must-revalidate');
          header('Pragma: hack');
          header('Content-Type: application/vnd.ms-excel');
          header('Content-Length: '.(string)(file size($file_path )));
          header('Content-Transfer-Encoding: binary\n');
          /*
          Using the "Content-Disposition" header allows us to provide a recommended filename
          as well as force the browser to display the save/open dialog.
          */
          header('Content-Disposition: attachment; filename="sugge stedfilename.cs v"');
          readfile($file_ path);
          ?>
          [/code]

          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

          Comment

          • shigehiro
            New Member
            • Oct 2006
            • 8

            #6
            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

            Comment

            Working...