• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Export dynamic table gen in jsp to excel

 
karthika nair
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1625
5
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
karthika nair
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem is the scriptlet tags appear in the excel and the actual dynamic result generated does not appear.
 
Swastik Dey
Rancher
Posts: 1625
5
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can try this
 
karthika nair
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1625
5
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Got the logic ---- Thanks to Swastik
page1
----------

Page2
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic