<%@ page contentType="application/vnd.ms-excel;
charset=UTF-8"
<head>
<%
String reportName = "myReport";
<script>
var REPORT_NAME = "<%= reportName ";
function toExcel() {
window.open( "excel.jsp?reportname=" + REPORT_NAME, REPORT_NAME +
"_excel", "height=400, width=600, scrollbars=yes, resizable=yes");
}
</script>
</head>
<body>
...
<a href="javascript:toExcel()" >Export to Excel</a>
<bloxreport:report id="report" bloxName="<"
interactive="true" errors="true" >
...
</bloxreport:report>
<!--Using the taglibs -->
<%@ taglib uri="bloxreporttld" prefix="bloxreport"
<!--Importing the associated java classes in order to use the APIs -->
<%@ page import="com.alphablox.blox.*"
<!-- Setting the contentType -->
<%@ page contentType="application/vnd.ms-excel; charset=UTF-8"
<%
//Set report to non-interactive mode so the menus don’t get rendered
String reportName = (String)request.getParameter( "reportname" );
if( reportName != null ) {
BloxContext context = BloxContextFactory.getBloxContext(request, response);
ReportBlox reportBlox = (ReportBlox)context.getBlox( reportName );
if( reportBlox != null ) {
reportBlox.setInteractive(false);
} else {
out.println( "The report " + reportName + " does not exist." );
}
} else {
out.println( "This page was called without a report name." );
}
<html>
<head>
<title><%= reportName Excel Report</title>
<%--In line the styles so they’ll be saved if the page is saved and
you are not asked to be authenticated--
<style>
<jsp:include page="style/reportstyles.css" flush="true"/>
</style>
</head>
<body>
<%--The reportblox tag that follows causes the html of the report to be
rendered --
<bloxreport:report id="reportBlox" bloxName="<" />
</body>
</html>
<head>
<style>
<jsp:include page="/AlphabloxServer/theme/styles.css" flush="true"/>
</style>
</head>
This ensures the report format and layout is preserved in Excel, no additional authentication is required, and Excel does not hang due to failure to resolve the style sheet import statements.