473,385 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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.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
5 4887
jlm699
314 100+
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
Thanks, jlm699 for your fast reply (as usual)...
:)

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

Shige
Mar 18 '08 #3
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
314 100+
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
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

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

Similar topics

0
by: Shawn Mehaffie | last post by:
I have the following class that I've wirtten to take a Dataset and automatically export it to either XML, ASCII or Tab delimited file. The reason I wrote it they way I did was that I don't want to...
1
by: Do Park via SQLMonster.com | last post by:
Hello all, I don?t often export data from a table. I am wondering how you export data from a table. I?d like to know how you export in real world. Do you export data from a table to a flat...
0
by: TheCoder | last post by:
I am making a D-base with web conectivity for my class project. I have everything working but the subit button sends the data to the correct fields but afterwards it wants to reproduce new blank...
0
by: Dave | last post by:
Is this possible? Here is my current code (which opens the pdf in Internet Explorer) Dim crReportDocument As CrystalDecisions.CrystalReports.Engine.ReportDocument Dim crExportOptions As...
0
by: Shawn Mehaffie | last post by:
I have the following class that I've wirtten to take a Dataset and automatically export it to either XML, ASCII or Tab delimited file. The reason I wrote it they way I did was that I don't want to...
3
by: Calvin KD | last post by:
Does anyone knows of any issues/problems associated with sending xml file via https? I have a button which exports data records using DataSet.GetXML() method and sending it over the https and...
2
by: zz12 | last post by:
Hello. I have negatives values showing as parenthesis when viewed on an asp page but when exported to excel as follows: Response.ContentType = "application/vnd.ms-excel" ...the negative values...
6
Cintury
by: Cintury | last post by:
Hi all, I've developed a mobile application for windows mobile 5.0 that has been in use for a while (1 year and a couple of months). It was developed in visual studios 2005 with a back-end sql...
4
by: Max2006 | last post by:
Hi, We are developing a SQL server based asp.net application. As part of requirement we should allow users import/export some relational data through web user interface. We are investigation...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.