カスタムエクスポートボタン

  • 作成者:ayuan0625
  • 編集回数:23次
  • 最終更新:ayuan0625 于 2021-11-01
  • 一.概要

    下図のように、Webページのカスタムボタンを通してエクスポートすることができます。

    二.iframeでページに埋め込む

    1.カスタム出力ボタン

    1.実現するJavaScriptコード

    次のようなJavaScriptコードによってFineReportの出力を実現できます。

     

    出力形式
    実現するコード

    PDF


    exportReportToPDF()

    Excel

    xlsxファイル、改ページエクスポート

    exportReportToExcel('page')

    xlsxファイル、標準エクスポート

    exportReportToExcel('simple')

    xlsxファイル、1ページ1シートエクスポート

    exportReportToExcel('sheet')

    xlsファイル、改ページエクスポート

    exportReportToExcel('page_isExcel2003')

    xlsファイル、標準エクスポート

    exportReportToExcel('simple_isExcel2003')

    xlsファイル、1ページ1シートエクスポート

    exportReportToExcel('sheet_isExcel2003')

    Word

    exportReportToWord()

    画像

    PNG

    exportReportToImage('png')

    JPG

    exportReportToImage('jpg')

    GIF

    exportReportToImage('gif')

    注:2016年10月10日前のJARファイルを対象にExcelへエクスポートするなら、デフォルトとしてxls形式にエクスポートされます。

    2.使用方法

    各ボタンのクリックイベントは、上述のJavaScriptコードを呼び出すことによってそれに対応した形式のファイルにエクスポートすべきです。

    例えば、PDFファイルにエクスポートするなら、出力ボタンのonclickイベントは次のようです。

    onclick="document.getElementById('reportFrame').contentWindow.contentPane.exportReportToPDF()"

    注:docment.getElementById('reportFrame')を通してiframeの要素を取得し、contentWindowによって帳票のウィンドウを取得します。さらに、contentPaneという帳票のコンテナを獲得することで、結果としてこのコンテナから各種のコードを呼び出してエクスポートを実現できるようになります。

    3.整ったHTMLファイル

    1.export.htmlを新規作成します。内容が次のようです。

    <html>
     <head>  
     <title>FineReportExport</title>  
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />  
     <script type="text/javascript" src="/webroot/decision/view/report?op=emb&resource=finereport.js"></script>
     </head>  
     <body>
    <button type="button" onclick="document.getElementById('reportFrame').contentWindow.contentPane.exportReportToPDF()">PDF</button>    
    <button type="button" onclick="document.getElementById('reportFrame').contentWindow.contentPane.exportReportToExcel('page')">Excel(Full page)</button>
    <button type="button" onclick="document.getElementById('reportFrame').contentWindow.contentPane.exportReportToExcel('simple')">Excel(Unaltered)</button>
    <button type="button" onclick="document.getElementById('reportFrame').contentWindow.contentPane.exportReportToExcel('sheet')">Excel(Page to Sheet)</button>
    <button type="button" onclick="document.getElementById('reportFrame').contentWindow.contentPane.exportReportToWord()">Word</button>
    <iframe id="reportFrame" width="100%" height="100%" name="reportFrame" src="/webroot/decision/view/report?viewlet=入門デモ.cpt&region=関東">
    </iframe>    
     </body>  
    </html>

    2.下図のように、export.htmlを%FR_HOME%\webapps\webroot\help\page_demoのパスに置きます。 

    2.リックジャック攻撃保護を無効に

    下図のように、FineReportポータルを開き、「システム-安全管理-セキュリティ保護-Security Headers-詳細設定」を順にクリックし、「クリックジャック攻撃保護」をオフにします。

    3.効果確認  

    サーバを開き、ブラウザに次のURLを入力すると、帳票を統合したWebページが表示されます。http://localhost:8075/webroot/help/page_demo/export.html

    下図のように、画面の上部にあるお望みのカスタム「出力ボタン」をクリックすると、それに対応した形式のファイルにエクスポートされます。

    Attachment List


    Theme: FineReport ディプロイ統合
    • いいね
    • 良くない
    • 閲覧しただけ