FineReport支持多種不同的匯出方式,直接使用FineReport內置匯出按鈕可以非常快捷方便的來對各種格式的輸出,但是我們在web頁面集成中的時候,往往只想將報表內容嵌入到iframe中,而工具列以及工具列上的按鈕都會隱藏掉,而使用web頁面自定義的按鈕,那么,此時,這種自定義按鈕如何實作匯出呢?
如上圖所示,新建一個html頁面,定義一個工具列和一個iframe,工具列中定義上圖所示的按鈕,iframe中嵌入FineReport中的報表,如下圖:
FineReport報表設定
打開設計器,找到上面web頁面中嵌入的那張模板,由于要使用自定義按鈕作為工具列,那么FineReport報表內置的工具列就無需顯示出來。點擊模板>模板web屬性>分頁預覽設定,去掉使用工具列前面的勾選,如下圖:
自定義匯出按鈕
Web頁面中定義了9個自定義匯出按鈕,那么怎樣才能實作匯出操作呢?
FineReport匯出操作的JS介面為:
匯出PDF:exportReportToPDF()
匯出[Excel](分頁):exportReportToExcel('page')
匯出[Excel](原樣):exportReportToExcel('simple')
匯出[Excel](分頁分sheet):exportReportToExcel('sheet')
匯出[Excel](分頁匯出xls格式):exportReportToExcel('page_isExcel2003')
匯出[Excel](原樣匯出xls格式):exportReportToExcel('page_isExcel2003')
匯出[Excel](分頁分sheet匯出xls格式):exportReportToExcel('page_isExcel2003')
匯出[圖片]:exportReportToImage('gif')【括號里面可以更換引數,比如說png,jpg等等圖片型別】
匯出[word]:exportReportToWord()
故,各個按鈕的點擊事件應用呼叫上述的JS介面來實作其對應的匯出格式,比如說匯出PDF,那么其按鈕的onclick時間為:
onclick="document.getElementById('reportFrame').contentWindow.contentPane.exportReportToPDF()"
docment.getElementById('reportFrame')是獲取到iframe框架,然后通過contentWindow得到報表視窗,并拿到contentPane這個報表容器,最后就可以從容器中呼叫各種匯出介面的方法了。
其他的幾個按鈕的匯出事件這里就不一一講解了。
完整代碼
根據上述同樣的方法為其他幾個按鈕添加匯出事件,完整代碼如下:
復制代碼
<html>
<head>
<title>FineReport自定義匯出</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<fieldset>
<div id="toolbar">
<button type="button" onclick="document.getElementById('reportFrame').contentWindow.contentPane.exportReportToPDF()">匯出[PDF]</button>
<button type="button" onclick="document.getElementById('reportFrame').contentWindow.contentPane.exportReportToExcel('page')">匯出[Excel](分頁)</button>
<button type="button" onclick="document.getElementById('reportFrame').contentWindow.contentPane.exportReportToExcel('simple')">匯出[Excel](原樣)</button>
<button type="button" onclick="document.getElementById('reportFrame').contentWindow.contentPane.exportReportToExcel('sheet')">匯出[Excel](分頁分sheet)</button>
<button type="button" onclick="document.getElementById('reportFrame').contentWindow.contentPane.exportReportToExcel('page_isExcel2003')">匯出[Excel](分頁匯出xls格式)</button>
<button type="button" onclick="document.getElementById('reportFrame').contentWindow.contentPane.exportReportToExcel('simple_isExcel2003')">匯出[Excel](原樣匯出xls格式)</button>
<button type="button" onclick="document.getElementById('reportFrame').contentWindow.contentPane.exportReportToExcel('sheet_isExcel2003')">匯出[Excel](分頁分sheet匯出xls格式)</button>
<button type="button" onclick="document.getElementById('reportFrame').contentWindow.contentPane.exportReportToImage('png')">匯出[圖片]</button>
<button type="button" onclick="document.getElementById('reportFrame').contentWindow.contentPane.exportReportToWord()">匯出[Word]</button>
</div>
</fieldset>
<iframe id="reportFrame" width="100%" height="100%" src='https://bbs.csdn.net/WebReport/ReportServer?reportlet=doc/Primary/DetailReport/Details.cpt' ></iframe>
</body>
</html>
效果查看
點擊不同的按鈕,即可看到其匯出的結果:
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/53519.html
上一篇:這個代碼怎么不能回圈
下一篇:BitBtn添加位圖顯示問題
