Results 1 to 5 of 5
  1. #1
    rajesh_grs is offline Member
    Join Date
    Mar 2011
    Posts
    2
    Rep Power
    0

    Default Export Excel which has more than 1 worksheet

    Guys,
    Anyone has any idea how to generate & stream an excel sheet in jsp.

    Please note: The excel sheet will have two worksheets inside & we should stream out the excel sheet to the user on JSP itself without storing the excel file on the applicatoin server.

    Action I performed: Our source is 2 csv files. I have used CSVReader to read those files & create excel sheet with two tabs using POI Libraries which is causing me to store excel sheet on the server.

    Need Help:
    How to generate an excel sheet which has more than one worksheets using JSP & also how to set that in the response.header ? Please advice

    Please let me know if my requirements are not clear. Appreiate your help.

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,049
    Rep Power
    20

    Default

    You don't do it using JSPs.
    You write a servlet that calls your code that creates the POI excel workbook.
    Then, instead of streaming that to a file to save it, you stream it to the response output stream, after setting the correct type in the header...which I'm sure google can help you with (it may even be application/excel, but I can't guarantee it).

  3. #3
    rajesh_grs is offline Member
    Join Date
    Mar 2011
    Posts
    2
    Rep Power
    0

    Default

    Tolls, thanks for replying.
    yes, it works well if we are streaming data to a single worksheet of an excel. Below is the code.
    response.setContentType("application/vnd.ms-excel");
    response.setHeader("Content-Disposition", "attachment; filename=somefilename.xls");
    response.setDateHeader("Expires",-1);

    But how would we handle if we want to have 2 worksheets in same excel. I think if we use POI Library,
    for instance HSSFWorkbook hwb = new HSSFWorkbook();
    then we will end up writing data to the file on the server
    hwb.write(fileOut); where FileOutputStream fileOut = new FileOutputStream(D:/filename.xls);

    In our case we should not store the file on the server.
    Any further help to solve this would be really appreciated.

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,049
    Rep Power
    20

    Default

    What's the difference between a Workbook with one sheet and one with two?
    You use Workbook.write(), passing in the response output stream.
    That'll send the entire workbook.

  5. #5
    dlorde is offline Senior Member
    Join Date
    Jun 2008
    Posts
    339
    Rep Power
    7

Similar Threads

  1. Replies: 0
    Last Post: 10-29-2010, 11:25 AM
  2. Export to excel
    By nehaa in forum AWT / Swing
    Replies: 1
    Last Post: 04-30-2009, 02:44 PM
  3. export to excel
    By diana glz in forum Advanced Java
    Replies: 0
    Last Post: 03-13-2008, 11:01 PM
  4. export to excel
    By diana glz in forum New To Java
    Replies: 0
    Last Post: 03-13-2008, 09:26 PM
  5. Reading excel worksheet
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-13-2008, 11:19 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •