Custom Batch-Export Button

  • Last update:February 25, 2026
  • Overview

    Application Scenario

    You can refer to the solution in this document when you have the following requirements:

    • All tables are placed in one Excel file, with different sheets.

    • Multiple general reports are exported as an Excel file through a single URL.

    • Dozens of different templates, each with different parameters, are batch-exported to Excel.

    • Multiple reports are exported in a single operation.

    Function Description

    This document provides methods for exporting multiple reports simultaneously to one specific format.

    iconNote:
    The methods in this document apply only to general reports.

    Implementation Method

    Code Example

    Add a piece of JS code to export only the data filtered from the file Template Parameter.cpt with the Region parameter value set to California, and data of Cross_Report-Data_Bidirectional_Expansion.cpt (containing no parameter) to Excel upon a button click. The code is as follows:

    http://localhost:8075/webroot/decision/view/report?reportlets=[{reportlet
    :"/doc-EN/Primary/Parameter/Template Parameter.cpt",Region: "California"}
    ,{reportlet:"/doc-EN/Primary/
    CrossReport/Cross_Report-Data_Bidirectional_Expansion.cpt"}]&format=excel&__filename__=export

    iconNote:

    The URL cannot be accessed directly, because browsers may not support special characters such as square brackets ([]) or curly braces ({}). Therefore, encoding conversion is required before direct access. The encoded version of the above code is:

    http://localhost:8075/webroot/decision/view/report?reportlets=%5B%7Breportlet%3A%22%2Fdoc-EN%2FPrimary%2FParameter%2FTemplate%20Parameter.cpt%22%2CRegion%3A%20%22California%22%7D%2C%7Breportlet%3A%22%2Fdoc-EN%2FPrimary%2FCrossReport%2FCross_Report-Data_Bidirectional_Expansion.cpt%22%7D%5D&format=excel&__filename__=export

    Code Description

    Use the window.open method to open a URL with an export parameter and export the report to Excel. The relevant parameters are as follows:

    ParameterExample

    (1) When the report contains no parameter:
     In [{reportlet:"/doc/reportname.cpt"},{reportlet:"/doc/reportname.cpt"},{...}],
    {reportlet:"/doc/reportname.cpt"} is the access path of the template.

    [{reportlet:"/doc-EN/Primary/Parameter/Template Parameter.cpt"},{reportlet:"/doc-EN/Primary/CrossReport/Cross_Report-Data_Bidirectional_Expansion.cpt"}]

    (2) When the report contains parameters:
    In [{reportlet:"/doc/reportname.cpt",paraname1:"paravalue1",paraname2:"paravalue2",...},{...}], paraname1 and paravalue1 refer to the parameter name and value used in the filter condition, and only the filtered template data will be exported. Multiple parameters are separated by commas.


    [{reportlet: "/doc-EN/Primary/Parameter/Template Parameter.cpt',Region: 'California'},{reportlet:"/doc-EN/Primary/CrossReport/Cross_Report-Data_Bidirectional_Expansion.cpt"}]

    &format = XX: XX specifies the format of the file generated after export.

    &format=excel: The result of the batch export is an Excel file containing multiple reports distributed in multiple sheets.

    &__filename__=name renames the file generated after export. name is the custom file name.

    &__filename__=export renames the file generated after export to export.

    Procedure

    Template Preparation

    Templates to be used:

    • FineReport installation directory\webapps\webroot\WEB-INF\reportlets\doc-EN\Primary\Parameter\Template Parameter.cpt

    • FineReport installation directory\webapps\webroot\WEB-INF\reportlets\doc-EN\Primary\CrossReport\Cross_Report-Data_Bidirectional_Expansion.cpt

    HTML File Creation

    (1) Add a piece of JS code to the HTML file to export only the data filtered from the file Template Parameter.cpt with the Region parameter value set to California, and data of Cross_Report-Data_Bidirectional_Expansion.cpt (containing no parameter) to Excel upon a button click. The code is as follows:

    var reportlets
     = "[{reportlet: '/doc-EN/Primary/Parameter/Template Parameter.cpt'
    ,Region: 'California'}, {reportlet: '/doc-EN/Primary/CrossReport/Cross_Report-Data_Bidirectional_Expansion.cpt'}]"     function clickEvent() {         
    window.open(encodeURI('/webroot/decision/view/report?reportlets=' + reportlets + '&format=excel'));     }

    The complete code is as follows.

    Click  export.rar to download the RAR file and decompress it to obtain the HTML file.

    iconNote:
    For a customized batch-export event, if multiple files are being downloaded simultaneously during the export process, you are advised to lower the browser's security level to prevent the file generated after export from being flagged as unsafe by the browser.

    <!DOCTYPE html><html
    lang
    ="en"><head>
        <meta
    charset="UTF-8">    <title>FineReport Custom Export</title></head><script type="text/
    javascript
    ">    var reportlets = "[{
    reportlet: '/doc-EN/Primary/Parameter/Template Parameter.cpt'
    ,Region: 'California'}, {reportlet: '/doc-EN/Primary/CrossReport
    /Cross_Report-Data_Bidirectional_Expansion.cpt'}]"    function clickEvent() {        window.open(encodeURI('/webroot/decision/view/report?reportlets='
     +
    reportlets
     +
    '
    &format=excel'));    }</script><body><button
            type="button"        onclick= clickEvent()>Export to [Excel]</button></body></html>

    (2) Place export.html under the path FineReport installation directory\webapps\webroot\help, as shown in the following figure.

    3.2新建HTML文件(2).png

    Effect Display

    Start the FineReport project, enter http://localhost:8075/webroot/help/export.html in the browser, and click Export to [Excel] to export reports to Excel. The effect is shown in the following figure.

    效果.gif

    Attachment List


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

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

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

    不再提示

    10s後關閉

    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