Solved

Excel sheet with JSP

Posted on 2003-12-07
5
1,056 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Suggested Solutions

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
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.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

734 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