Custom Export Button

  • Last update:December 22, 2020
  • I. Overview

    1. Requirement

    When add a report to a web page, how to export the report using a custom button? Take the following steps:

    Sample 1:

    Sample 2:


    2. Solution

    If a report is embedded into a web page with iframe, you can call the export methods built in FineReport using JavaScript. If the template to be exported is not embedded in the web page, use window.open to access a URL with export parameters to export the report.


    II. Steps

    1. Sample 1

    If a report is embedded in iframe, JS Custom Button Export  on the HTML page can use the FR-built-in export functions to export the report, for example, Export as PDF, Export as Excel (Pagination), Export as Excel (Original), Export as Excel (with multiple pages and sheets), Export as Word and so on.

    Input the following codes:

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

    Input the following complete HTML codes:

    <html>
      <head>  
      <title>FineReportExport</title>  
      <meta http-equiv="Content-Type" content="text/htmlcharset=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=doc-EN/Primary/Parameter/Parameter_Reference.cpt&region=East China">
    </iframe>    
      </body>  
    </html>
    Show Code


    2. Sample 2

    If the report is not embedded into iframe or the report exported is different from the one in preview, use window.open().

    Modify the onclick event for the button by inputting the following codes:

    <button type="button" onclick="window.open(encodeURI('/webroot/decision/view/report?viewlet=doc-EN/Primary/Parameter/Parameter_Reference.cpt&region=East China')+'&format=excel')">Excel</button>

    Input the following complete HTML codes:

    <html>
      <head>  
      <title>FineReportExport</title>  
      <meta http-equiv="Content-Type" content="text/htmlcharset=UTF-8" />  
      <script type="text/javascript" src="/webroot/decision/view/report?op=emb&resource=finereport.js"></script> 
      </head>  
      <body>
    <button type="button" onclick="window.open(encodeURI('/webroot/decision/view/report?viewlet=doc-EN/Primary/Parameter/Parameter_Reference.cpt&region=East China')+'&format=excel')">Excel</button>

    <button type="button" onclick="window.open(encodeURI('/webroot/decision/view/report?viewlet=doc-EN/Primary/Parameter/Parameter_Reference.cpt&region=East China')+'&format=pdf')">PDF</button>
    <button type="button" onclick="window.open(encodeURI('/webroot/decision/view/report?viewlet=doc-EN/Primary/Parameter/Parameter_Reference.cpt&region=East China')+'&format=word')">Word</button>
    <iframe id="reportFrame" width="100%" height="100%" name="reportFrame" </iframe>  
      </body>  
    </html>

    Note: For any information about cross domain, please refer to Cross Domain JS Calls  and JS Cross Domain Solution.


    III. Download templates

    Template for Sample 1:

    cusexport1.html


    Template for Sample 2:

    cusexport2.html


     

     

     

     

     

     

     

     


    Attachment List


    Theme: Deployment and Integration
    • Helpful
    • Not helpful
    • Only read

    滑鼠選中內容,快速回饋問題

    滑鼠選中存在疑惑的內容,即可快速回饋問題,我們將會跟進處理。

    不再提示

    8s后關閉

    Get
    Help
    Online Support
    Professional technical support is provided to quickly help you solve problems.
    Online support is available from 9:00-12:00 and 13:30-17:30 on weekdays.
    Page Feedback
    You can provide suggestions and feedback for the current web page.
    Pre-Sales Consultation
    Business Consultation
    Business: international@fanruan.com
    Support: support@fanruan.com
    Page Feedback
    *Problem Type
    Cannot be empty
    Problem Description
    0/1000
    Cannot be empty

    Submitted successfully

    Network busy