on 08-17-2005 3:51 PM
I'm having trouble getting a jsp page to display in Excel. Below is the code. Any idea what I'm missing?
Thanks in advance,
John
<%@ taglib uri= "tagLib" prefix="hbj" %>
<jsp:useBean id="rbpTable" scope="application" class="com.halliburton.esg.erp.zelc.bdvipp.htmlb.ViewRevenueByParticipantTable" />
<%
request.getServletResponse(false).setContentType("application/vnd.ms-excel");
request.getServletResponse(false).setHeader("Content-Type","application/vnd.ms-excel");
request.getServletResponse(false).setHeader("Content-Disposition", "attachment; filename=test.xls");
%>
<hbj:content id="myContext" >
<hbj:document>
<hbj:documentHead title="sap">
<meta http-equiv="Content-Type" content="application/x-msexcel; charset=ISO-8859-1">
</hbj:documentHead>
<hbj:page title="Template for a portal component">
<hbj:form id="myFormId">
<hbj:button
id="printButton"
text="Print"
tooltip="Print"
onClientClick="javascript:window.print();"
width="10"
design="EMPHASIZED">
</hbj:button>
<hbj:button
id="closeButton"
text="Close"
tooltip="Close"
onClientClick="javascript:window.close();"
width="10"
design="EMPHASIZED">
</hbj:button>
<BR><BR>
<%
java.text.DecimalFormat df = new java.text.DecimalFormat("#,##0");
String revenueString = "Total Assigned Revenue: $"+df.format(rbpTable.getTOTAL_PLAN());
%>
<hbj:textView text="<%=revenueString%>" design="EMPHASIZED" />
<hbj:tableView
id="myTableView"
model="rbpTable.model"
design="STANDARD"
headerVisible="true"
footerVisible="false"
fillUpEmptyRows="false"
selectionMode="NONE"
visibleFirstRow="1">
</hbj:tableView>
</hbj:form>
</hbj:page>
</hbj:document>
</hbj:content>
It´s so easy print your results from a JSP in excel.
By default the mime type of the jsp is HTML, but you can change it, only have to add the next line in your jsp.
<%@ page contentType="application/vnd.ms-excel" %>
that is a example that you can try :
<%@ page contentType="application/vnd.ms-excel" %>
1997 1998 1999
12.3 13.4 14.5
will load Excel and show this:
A B C
1
2
3 1997 1998 1999
4 12.3 13.4 14.5
Good luck!
Josue Cruz
PS.Dont forget to reward points
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
what problems do you have ?
Doesn't show the page at all or is the result not what you are expecting ? Any error messages ?
I guess without some more information no-one will be able to help you.
Regards, Astrid
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
81 | |
9 | |
9 | |
7 | |
7 | |
6 | |
6 | |
6 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.