-
How to output JSP page to Excel ? (14 messages)
- Posted by: Little Bee
- Posted on: September 01 2005 21:02 EDT
Result is displayed in the JSP and there is a button on the JSP which I want to output the result to Excel file when clicked. How to do that ?
Thanks...Threaded Messages (14)
- POI can help u out by liu yu on September 02 2005 00:05 EDT
- sample code, pls (Urgent) by Little Bee on September 02 2005 02:02 EDT
- How to output JSP page to Excel ? by Ashish Jamthe on September 02 2005 00:30 EDT
- to open in jsp first then click button to open in Excel by Little Bee on September 02 2005 01:58 EDT
- How to output JSP page to Excel ? by Arturo García Martín on September 02 2005 03:41 EDT
- Try with this by kishore kumar on September 02 2005 06:19 EDT
- How to output JSP page to Excel ? by Michael Miller on September 02 2005 10:10 EDT
- using hidden fields by Little Bee on September 04 2005 23:07 EDT
- Is it working? by David Selvaraj on October 04 2005 11:43 EDT
- Excel in jsp * this works by Nisal Kooragoda on August 02 2007 04:47 EDT
- export data to excel using jsp by jayant kashid on August 14 2009 11:01 EDT
- Export JSP to Excel by Vineet Rao on September 13 2012 14:26 EDT
- Export JSP to Excel by Vineet Rao on September 13 2012 14:35 EDT
- How to output JSP page to Excel ? by Gheorghe Bucsariu on March 13 2014 05:18 EDT
-
POI can help u out[ Go to top ]
- Posted by: liu yu
- Posted on: September 02 2005 00:05 EDT
- in response to Little Bee
i think you can use the apache POI, here is the link http://jakarta.apache.org/poi/index.html -
sample code, pls (Urgent)[ Go to top ]
- Posted by: Little Bee
- Posted on: September 02 2005 02:02 EDT
- in response to liu yu
Trying to digest what is in the apache (POI) website, but lost.
can someone kindly provide sample code on how to use POI to export the result on JSP to Excel ? and also what to download for POI ?
Thanks... -
How to output JSP page to Excel ?[ Go to top ]
- Posted by: Ashish Jamthe
- Posted on: September 02 2005 00:30 EDT
- in response to Little Bee
One way would be to present your output in csv format and have the browser open it in excel.
From memory the code looked like this.
response.reset();
response.setHeader("Content-type","application/xls");
response.setHeader("Content-disposition","inline; filename=nombre.csv");
PrintWriter op = response.getWriter();
String CSV = "Cola1" + "," + "Cola2" + "Cola3" + + "\r\n";
CSV += "Colb1" + "," + "Colb2" + "Colb3" + + "\r\n";
CSV += "Colc1" + "," + "Colc2" + "Colc3" + + "\r\n";
op.write(CSV.getBytes());
Additionally, I guess I had to do a file mapping at the desktop mapping .csv files to Excel application.
Regards,
Ashish Jamthe
TRL, Telstra -
to open in jsp first then click button to open in Excel[ Go to top ]
- Posted by: Little Bee
- Posted on: September 02 2005 01:58 EDT
- in response to Ashish Jamthe
What I need is to first display the result in JSP and to display in Excel when button "Export to Excel" is clicked ? So I believe the following will display the result as Excel without displaying in JSP, right ?
response.reset();
response.setHeader("Content-type","application/xls");
response.setHeader("Content-disposition","inline; filename=nombre.csv");
......... -
How to output JSP page to Excel ?[ Go to top ]
- Posted by: Arturo García Martín
- Posted on: September 02 2005 03:41 EDT
- in response to Little Bee
Hi all.
Try with this sample code:
[BEGIN FILE: excel.jsp]
<%
response.reset();
response.setHeader("Content-type","application/xls");
response.setHeader("Content-disposition","inline; filename=nombre.csv");
%>Col-A1,Col-A2,Col-A3
Col-B1,Col-B2,Col-B3
Col-C1,Col-C2,Col-C3
[END FILE: excel.jsp]
Save to a file into a java-enabled webserver "visible path" (like Tomcat) an call it with a browser.
C U -
Try with this[ Go to top ]
- Posted by: kishore kumar
- Posted on: September 02 2005 06:19 EDT
- in response to Little Bee
Hi,
Hope, it will work for you..
copy the contents in a string like..
------------------------------------
recordString.append("<HTML><body><table>");
recordString.append("<tr><td>hello</td></tr>");
recordString.append("</table>");
String str = recordString.toString();
response.setContentType("application/vnd.ms-excel");
PrintWriter pw=response.getWriter();
pw.println(str);
----------------------------------- -
How to output JSP page to Excel ?[ Go to top ]
- Posted by: Michael Miller
- Posted on: September 02 2005 10:10 EDT
- in response to Little Bee
If you want a quick and easy way to output data to excel you can use the displaytag library (www.displaytag.org). Other than that you can use POI, Coccoon or an API called JXL.
M -
using hidden fields[ Go to top ]
- Posted by: Little Bee
- Posted on: September 04 2005 23:07 EDT
- in response to Michael Miller
Hi,
For displayTag, must have data as list ? My output is multiple tables which cannot be created just by list. So, is it true that I cannot use displayTag ?
What I'm doing now is to have hidden fields created on the JSP page which displays the result. Hidden fields will contain the result. On click of the button, another JSP will loop through all the hidden field and output to Excel. This page has <%@ page contentType="application/vnd.ms-excel"%>.
The problem is :
The result is very long (took about 11 minutes to be displayed). Therefore, many hidden fields are created. After result is displayed, when I click on other button to launch other page, it takes > 1 minute and my client machine shows 100% CPU. Why is this so ? there is a limit on number of hidden fields ? -
Is it working?[ Go to top ]
- Posted by: David Selvaraj
- Posted on: October 04 2005 11:43 EDT
- in response to Little Bee
I've a similar requirement and would like to know whether you were able to do it.,
Please let me know whether you're able to make it working..
Thanks -
Excel in jsp * this works[ Go to top ]
- Posted by: Nisal Kooragoda
- Posted on: August 02 2007 04:47 EDT
- in response to Little Bee
I spend a day to find out this solution My application has excel porting from java code using POI. once the excel in generated i wanted to click open excel from the server folder (not on web root) using the client side browser. In my case there were 2 types of reports one direcly generate the report and using the jsp you can click open, the other version had a page redirect after the report generation. the version one (call generate routine and try to open it on the same jsp page) comes with funny characters, where as the second version generate the Excel and redirect to another jsp works fine so the issue is the Mime and the way each browser cache them.you can see the original name of the report shows as report.xls --> report[1].xls and have funny characters so you have to redirect it to a jsp page which only does the call of excel here is a code sniff A.jsp ///////////////////////////////////////////////////////// String fullPath_filename = myobject.generateExcelreport(OutputPath,ProjectId,ReportId); response.sendRedirect("exportPrjojectData.jsp?reportname=" + fullPath_filename) //////////////// end of page A ////////////////////////////////////////////////////////// Page B //######### Obtaining Path String filepath =request.getParameter("reportname"); if(filename!=null&&filepath!=null) { console.printToConsole1("Printing to Excel Now ...!",filename); response.setContentType("APPLICATION/OCTET-STREAM"); response.setHeader("Content-Disposition", "attachment; filename=\"" + filename + "\""); java.io.FileInputStream fileInputStream = new java.io.FileInputStream(filepath + filename); int i; while ((i=fileInputStream.read()) != -1) { out.write(i); } fileInputStream.close(); out.close(); } // end of B.jsp /////////////////////////////////////////////////////////// -
export data to excel using jsp[ Go to top ]
- Posted by: jayant kashid
- Posted on: August 14 2009 11:01 EDT
- in response to Little Bee
In my application data is getting export to excel sheet but it is not in proper way as generally excel sheet looks. I mean if i want particular string in particular cell,how do i do that? Please reply urgent!! i used tag and i am printing a table on sheet.please help me.. -
Export JSP to Excel[ Go to top ]
- Posted by: Vineet Rao
- Posted on: September 13 2012 14:26 EDT
- in response to Little Bee
Its fairly simple and can be done with minimum changes to your existing JSP. Take a look at this example on quicklyjava.com:
http://www.quicklyjava.com/export-web-page-to-word/
-
Export JSP to Excel[ Go to top ]
- Posted by: Vineet Rao
- Posted on: September 13 2012 14:35 EDT
- in response to Vineet Rao
Ignore the link in the previous post, here is the correct link:
-
How to output JSP page to Excel ?[ Go to top ]
- Posted by: Gheorghe Bucsariu
- Posted on: March 13 2014 05:18 EDT
- in response to Little Bee
I know that POI is hard to digest and you can try EasyXLS, more specific, the JSP excel library version.
Check here a sample about how to output the Excel file:
http://www.easyxls.com/manual/html/programmerGuide/basics/cellvalues.html