?
Solved

Excel sheet with JSP

Posted on 2003-12-07
5
Medium Priority
?
1,061 Views
Last Modified: 2008-03-04
Hi There,
I want to convert my dynamic HTMl table(in this table data will be dynamically generated by JSP page) in a MS-Excel sheet and print it.
Can any body suggest me the way?
I already used
<%@ page contentType = "application/vnd.ms-excel" %>
<%response.setContentType("application/vnd.ms-excel");%>
but it is converting my whole JSP page into Excel sheet and I don't want the whole page just the table from this page.
Is it possible?

Thanks in advance

0
Comment
Question by:m_sharma98
3 Comments
 
LVL 26

Accepted Solution

by:
rdcpro earned 160 total points
ID: 9894900
Well, what I've done is to place a link on the page that causes the page to open in a new window, with the mime type set as you describe, but without any other HTML.  For example, this page:

http://myserver.com/foobar.jsp

shows the whole page.  When the user clicks the "download to Excel" link, the page reloads in a new window using a URL like:

http://myserver.com/foobar.jsp?output=excel

and in your JSP page you test for the value of the querystring before you render the page head and the parts of the body that are not part of the table.  If it's there, then you just set the mime type, and render ONLY the HTML table you want.

Regards,
Mike Sharp
0
 
LVL 15

Expert Comment

by:dualsoul
ID: 9895068
hm...as i understan you want part of your page to be Excel sheet?
i don't think you can do it,
you can rener standalone page, which contains only Excel stuff, and set approporiate mime-type for it.
 
  You can use Jakarta POI package, for creating Excel .xls files on the server side.
0
 
LVL 9

Assisted Solution

by:sparkplug
sparkplug earned 160 total points
ID: 9895514
You can display an Excel spreadsheet within your HTML output using frames. Move the code for generating the Excel document to another page, called for example 'generatexml.jsp'. Put an <iframe> tag on the first page with the 'src' attribrute set to the name of the Excel generating file as follows:  

<html>
<body>
<p>Some text here</p>
<iframe src="generateexcel.jsp" />
<p>Some more here</p>
</body>
</html>

Not all browsers support iframes. If you need to support older browsers you can use normal frames. e.g

<html>
<frameset rows="100, *, 100">
  <frame src="header.jsp">
  <frame src="generateexcel.jsp">
  <frame src="footer.jsp">
</frameset>
</html>

Hope this helps,

>S'Plug<
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Screencast - Getting to Know the Pipeline
Suggested Courses
Course of the Month15 days, 10 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question