Click to See Complete Forum and Search --> : How to generate csv from web page


saji
01-11-2005, 09:05 PM
Hi,

Do you know the best method to take reports in CSV. My idea is to save the report displayed in a web page into CSV format.

Thanks in advance,
Regards,
Saji John.

saji
01-11-2005, 09:37 PM
Dear all,

I forgot to mention that I am using JAVA/JSP as development tool.

Regards,
Saji

ray326
01-12-2005, 01:20 AM
What do you want to do, have a button on a page displaying a report that you click to download a CSV file of the data contained in that report?

saji
01-12-2005, 02:21 AM
Originally posted by ray326
What do you want to do, have a button on a page displaying a report that you click to download a CSV file of the data contained in that report?

Yes. I want to do the same.
Please help me.

Regards,
Saji.

ray326
01-12-2005, 09:07 AM
Is the result set passed to the JSP as a bean in the request?

saji
01-12-2005, 10:58 PM
Originally posted by ray326
Is the result set passed to the JSP as a bean in the request?

Yes, the bean returns the results(fields) either as a vector or an array. Then from the JSP, I have to loop through the vector and call another class/methods to get the related fields.

For example, in the case of a report that shows the members first name,last name,pin code according to certain criteria, the bean returns the member's IDs in a vector. Then from the JSP, to get the other details(first name,last name,pin code) call the member class by passing the corresponding id. using the public methods in the class (memberclass.getFirstname), the report is displayed.

Hope you can help me.

Thank you for the effort,

Regards,
Saji john.

ray326
01-13-2005, 01:04 PM
Ok, the strategy I'd try first is to add a parameter for the report query servlet so once it gets the result it can decide whether to forward to the current jsp or to a different jsp that will be the csv generator. Many folks don't realize that a JSP doesn't HAVE to write HTML. On this new page you'd set the content type to text/csv then code the csv file in the jsp.

saji
01-18-2005, 10:22 PM
Originally posted by ray326
Ok, the strategy I'd try first is to add a parameter for the report query servlet so once it gets the result it can decide whether to forward to the current jsp or to a different jsp that will be the csv generator. Many folks don't realize that a JSP doesn't HAVE to write HTML. On this new page you'd set the content type to text/csv then code the csv file in the jsp.

Dear sir,

Do you mean i can generate csv from JSP by setting the content type to text/csv?. So, will the output of the jsp will create csv file instead of HTML to browser?

If so could you please get me a sample code that generate the csv.

Thanks and regards,
Saji John.

ray326
01-18-2005, 10:49 PM
Yes, that's one way of doing it. After setting the content type you just "code" csv the same way you "code" a jsp. Your example bean (member) in one row would be:

"<%=member.getFirstName()%>","<%=member.getLastName()%>","<%member.getPin()%>"

I.e., the page would work just like an HTML JSP but the "language" or "markup" of the page would be CSV rather than HTML.

saji
01-21-2005, 04:39 AM
Originally posted by ray326
Yes, that's one way of doing it. After setting the content type you just "code" csv the same way you "code" a jsp. Your example bean (member) in one row would be:

"<%=member.getFirstName()%>","<%=member.getLastName()%>","<%member.getPin()%>"

I.e., the page would work just like an HTML JSP but the "language" or "markup" of the page would be CSV rather than HTML.

Dear sir,
Thank you very much. It works and when I execute the page it asks for saving the file and I can put a name with csv extension. One problem I found is that when I opened the file in excel, it does not show the cell boarder. I believe there should be some parameters to make the columns visible. Iam studying the same. If you can help, please..

Once again, thank you very much for the right advice.

regards,
Saji John.

ray326
01-22-2005, 10:55 AM
Any styling would have to be done in Excel.