Are you exporting it to the client, or are exporting it into a file on the server?
Regardless you can generate the csv by adding a new line for every row, and each column should be seperated with comma(,)
So, a csv file will look like this
You can look at any csv file by opening it in notepad
If you are exporting to client, you can set the content type and write the above text to the response(like Ben said) If you have to save it on the server, create an FileOutputStream and write the text out
Joined: Jun 11, 2004
what should i set the content type to, for CSV exporting? for Excel, i do set it it: application/vnd.ms-excel, what should it be for CSV?
Well, what i meant was: when i was using mimeypte as: application/vnd.ms-excel, it is prompting me to save in XLS format, but when i change the mimetype to: text/csv or text/plain, I assume it will prompt me to save it csv format (filename.csv), but it was displaying the results on my web page. How can I save the file in csv format, not in excel.
Set the mime type to something that the browser doesn't have an association for, like: "application/octet-stream" Then set the content disposition tag with "attached" and your filename. [ May 17, 2005: Message edited by: Ben Souther ]
Hi, I have a JSP that exports data to a CSV file. However, when I get the downloaded CSV file, there are trailing white spaces above the text. How can I get rid of those white spaces? I would appreaciate your help!
Originally posted by bala kiran: can you please get me sample code?
I just tried with this code using several different values for the content-type header on Fire Fox (FF).
It looks like FF first reads the Content-Type and prompts me to open with the application that is associated with that type. If if there is no registered app for that type, it then reads the extension set in the Content-Disposition tag and figures out that it's CSV file. It prompts me to save or open with Open Office which is what I've got registered for CSVs. I haven't tried with MSIE or any box that has MS-Office.