How to output JSP page to Excel ?


Web tier: servlets, JSP, Web frameworks: How to output JSP page to Excel ?

  1. How to output JSP page to Excel ? (14 messages)

    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 ?


    Threaded Messages (14)

  2. POI can help u out[ Go to top ]

    i think you can use the apache POI, here is the link
  3. sample code, pls (Urgent)[ Go to top ]

    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 ?

  4. How to output JSP page to Excel ?[ Go to top ]

    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.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";


    Additionally, I guess I had to do a file mapping at the desktop mapping .csv files to Excel application.

    Ashish Jamthe
    TRL, Telstra
  5. 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.setHeader("Content-disposition","inline; filename=nombre.csv");
  6. Hi all.

    Try with this sample code:

    [BEGIN FILE: excel.jsp]
    response.setHeader("Content-disposition","inline; filename=nombre.csv");
    [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
  7. Try with this[ Go to top ]


    Hope, it will work for you..

    copy the contents in a string like..
    String str = recordString.toString();
    PrintWriter pw=response.getWriter();

  8. How to output JSP page to Excel ?[ Go to top ]

    If you want a quick and easy way to output data to excel you can use the displaytag library ( Other than that you can use POI, Coccoon or an API called JXL.

  9. using hidden fields[ Go to top ]

    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/"%>.

    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 ?
  10. Is it working?[ Go to top ]

    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..

  11. Excel in jsp * this works[ Go to top ]

    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 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 + "\""); fileInputStream = new + filename); int i; while (( != -1) { out.write(i); } fileInputStream.close(); out.close(); } // end of B.jsp ///////////////////////////////////////////////////////////
  12. export data to excel using jsp[ Go to top ]

    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..
  13. Export JSP to Excel[ Go to top ]

    Its fairly simple and can be done with minimum changes to your existing JSP. Take a look at this example on



  14. Export JSP to Excel[ Go to top ]

    Ignore the link in the previous post, here is the correct link:


  15. 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: