Solved

Excel sheet with JSP

Posted on 2003-12-07
5
1,046 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

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…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

760 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

21 Experts available now in Live!

Get 1:1 Help Now