Solved

Excel sheet with JSP

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

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

Suggested Solutions

Title # Comments Views Activity
XML filtering Windows Event Viewer 10 61
Fixing Non-Standard characters in text 8 111
SQL XML ALL Nodes Compare in function 2 37
what are list of ebay api errors 1 28
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…
Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

856 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