Solved

Excel sheet with JSP

Posted on 2003-12-07
5
1,048 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
5 Comments
 
LVL 26

Accepted Solution

by:
rdcpro earned 40 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 40 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
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. 
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

930 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now