wood burning stoves 2.0*
The moose likes JSP and the fly likes Export dynamic table gen in jsp to excel Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Export dynamic table gen in jsp to excel" Watch "Export dynamic table gen in jsp to excel" New topic
Author

Export dynamic table gen in jsp to excel

karthika nair
Greenhorn

Joined: Mar 10, 2011
Posts: 5
Hello,
i have a jsp page that generates an html table dynamically and i want to export this table to excel on click of a button after the table has been viewed on the browser.
Solutions I have tried:
1)i read about the response.setContentType("application/vnd.ms-excel"),but how do i use a button to do this and export only that table and not any other data.
2)I tried javascript also but it works only with static table.
Now the only possible soln I feel is to somehow get only the table included in a new jsp and then use 1st option on the new page.But the problem is i don't know how to include only the table under div tag in a new jsp page?
Wish to get the solution soon.
Thanks
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1449
    
    6

2)I tried javascript also but it works only with static table.


If it works with static table, whats wrong with dynamic table. Because in the rendered html page whatever you get is static.


Swastik
karthika nair
Greenhorn

Joined: Mar 10, 2011
Posts: 5
The problem is the scriptlet tags appear in the excel and the actual dynamic result generated does not appear.
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1449
    
    6

You can try this
karthika nair
Greenhorn

Joined: Mar 10, 2011
Posts: 5
I had tried exactly this,but it does not show the dynamicly gen result but instead displays the code with scriptlets that I had written in order to get the desired output.
Pl. somehow get a solution to include only a fragment of a page ie table in another jsp page like we use <jsp:include> or <@include> directive
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1449
    
    6

May be you could do something like this
page1.jsp
----------


page2.jsp
--------


I have used scriptlets, but we should not. Better to use el, jstl.
karthika nair
Greenhorn

Joined: Mar 10, 2011
Posts: 5
Thanks a lot Swastik for taking time and working on grey cells to find a solution.You solved my problem partially.

The problem is I have many reports to be generated containing these kind of tables and at the end on the last row I have computed the total and stuff like that.So I can't create a common loop structure for all the reports as shown in your page2.jsp

So what I wanted was a common page with response type set to excel which all these reports can refer.

Below is given a common code that I am using to print the reports.Notice the use of div tag.I want something similar to it to work for my export feature as well like a jsp that can include just the contents of the div tag,etc
Pl. find a solution soon ...


karthika nair
Greenhorn

Joined: Mar 10, 2011
Posts: 5
Got the logic ---- Thanks to Swastik
page1
----------

Page2
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Export dynamic table gen in jsp to excel
 
Similar Threads
JSP File Download
Exporting HTML-Table data to EXCEL sheet
How to Export web page(jsp page) to excel using jsp or servlets
Saving data to Excel files
How to export data in excel