cancel
Showing results for 
Search instead for 
Did you mean: 

Displaying jsp page in Excel

Former Member
0 Kudos

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">

&nbsp;&nbsp;

<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>

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

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

Former Member
0 Kudos

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