有一些客戶希望在一個頁面打開數據鉆取的全部內容,這個功能可以利用iframe在自定義瀏覽界面解決,下面以一個簡單的例子來說明:
1. 創建子模板son
1.1 打開Java報表工具設計器,新建工作簿,添加參數獲取數據集SELECT * FROM STSCORE where classno = '${class}',設置參數class默認值Class1,合并A1至F12單元格,插入柱狀圖,綁定數據如下表:
1.2 下一步去掉iframe里的工具欄:打開報表|報表Web屬性|分頁預覽設置,清空所有按鈕,取消頁面樣式
1.3 保存模板到%FR_HOME%\WebReport\WEB-INF\reportlets\son.cpt
2. 創建主模板father
2.1 新建工作簿,獲取數據集SELECT * FROM STSCORE,配置數據如下表:
2.2 右擊A2單元格,設置超級鏈接,增加網絡報表1,選擇網絡報表%FR_HOME%\WebReport\WEB-INF\reportlets\son.cpt。取消顯示在原有報表頁面的勾選,在網絡報表頁面顯示樣式右邊的空白輸入inner2,插入報表參數class的值為A2,如圖
2.3 去掉iframe里的工具欄,具體操作同子模板son
2.4 稍作美觀,保存模板到%FR_HOME%\WebReport\WEB-INF\reportlets\father.cpt
3. 創建HTML文件iframe.html,源代碼如下:
<html>
<head>
<title>自定義瀏覽頁面</title>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<script type="text/javascript" src="/WebReport/ReportServer?op=resource&resource=/com/fr/web/jquery.js"></script>
<script type="text/javascript">
window.onload = function(){
reportFrame = document.getElementById("reportFrame").contentWindow.contentPane;
reportFrame.on("afterload", function(){
// currentPageIndex是從1開始的
var cPageIndex = reportFrame.currentPageIndex;
var pv = "第" + cPageIndex + "頁/共" + reportFrame.reportTotalPage + "頁";
$("#pnum").val(pv);
});
}
</script>
</head>
<body>
<div id="toolbar" >
<button type="button" onclick="reportFrame.gotoFirstPage()">首頁</button>
<button type="button" onclick="reportFrame.gotoPreviousPage()">上一頁</button>
<input id="pnum" type="text" readonly="true" style="width:80px">
<button type="button" onclick="reportFrame.gotoNextPage()">下一頁</button>
<button type="button" onclick="reportFrame.gotoLastPage()">末頁</button>
<button type="button" onclick="reportFrame.pageSetup()">頁面設置</button>
<button type="button" onclick="reportFrame.pdfPrint()">客戶端PDF打印</button>
<button type="button" onClick="reportFrame.flashPrint()">客戶端FLASH打印</button>
<button type="button" onclick="reportFrame.printReportServer()">服務器打印</button>
<button type="button" onClick="reportFrame.exportReportToExcel('page')">導出[Excel](分頁)</button>
<button type="button" onClick="reportFrame.exportReportToWord()">導出[Word]</button>
<button type="button" onclick="reportFrame.exportReportToPDF()">導出[PDF]</button>
<button type="button" onclick="reportFrame.emailReport()">郵件</button>
</div>
<p align="center">
<iframe id="reportFrame" src="/WebReport/ReportServer?reportlet=father.cpt" frameborder="0" width = "800" height = "128" ></iframe>
<iframe id="inner2" name="inner2" frameborder="0" width = "800" height = "300"></iframe>
</p>
</body>
</html>
注意:其中代碼<iframe id="inner2" name="inner2" frameborder="0" width = "800" height = "300"></iframe>表示把主模板鏈接的子模板顯示在一個iframe中
4. 預覽
打開內置服務器,在瀏覽界面輸入URL地址:
http://localhost:8075/WebReport/iframe.html,效果如圖:

這樣,鏈接的報表直接出現在了被鏈接的報表下面
文章轉自:http://blog.vsharing.com/fanfanzheng/A1385794.html
了解Java報表工具就從這里開始
posted on 2011-07-30 12:33
season 閱讀(584)
評論(0) 編輯 收藏 所屬分類:
Java報表—技術知識