Exporting Multiple Files in Batches Based on Parameters

  • Last update:February 25, 2026
  • Overview

    Expected Effect

    In actual business scenarios, you may want to filter data from the current table and export filtered data into multiple files separately, as shown in the following figure.

    效果.gif

    Implementation Method

    You can add a button widget to the parameter panel, configure a click event for it, obtain the selected parameters in the drop-down checkbox widget, and click the button to batch export the current table.

    Example

    Data Preparation

    Create a general report and create a data query named ds1 with the SQL statement:

    SELECT * FROM Inventory

    where 1=1 ${if(len(Warehouse) == 0,"","and Warehouse in ('" + Warehouse + "')")}

    where 1=1 means that the condition is always true, preventing errors caused by the absence of valid content after the WHERE clause when no parameter condition exists.

    len(warehouse)==0 indicates that the parameter Warehouse is empty.

    Warehouse in and Warehouse in ('" + warehouse + "') represents the obtained parameter value, and + is the string concatenation symbol.

    The query statements:

    If the value of the parameter Warehouse is empty, the query statement is SELECT * FROM Inventory.

    If the value of the parameter Warehouse is not empty, the query statement is SELECT * FROM Inventory WHERE 1=1 and Warehouse in ('${Warehouse}').

    2.1 数据准备.png

    On the designer menu bar, choose Template > Template Parameter. Create template parameters Opening and Closing, and left the default values empty, as shown in the following figure.

    2.1 数据准备(2.png

    Report Design

    Design the report, as shown in the following figure.

    2.2 报表设计.png

    Note: You need to add a filter condition for the A5 cell where the warehouse data column is located, to display data based on parameters. Conditions should be connected with and, as shown in the following figure.

    2.2 报表设计(2.png

    Widget Setting

    (1) Enter the parameter panel and add all parameters to the parameter panel.

    2.3 控件设置(1·.png

    (2) Set the Opening and Closing parameter widgets to Date widgets and set the default values, respectively.

    2.3 控件设置(2.png

    (3) Set the Warehouse parameter widget to a Drop-down Checkbox widget, set Database Table in Data Dictionary to the Inventory table in the FRDemo database for the widget, and set both Actual Value and Display Value to Warehouse. Select Returned Value's Type to String and manually enter "," for Separator.

    2.3 控件设置(3.png

    (4) Change the query button name to Generate Inventory Ledger.

    (5) Drag a Button widget to the panel and rename it to Batch Export. Adjust the widget positions, and the final effect is as shown in the following figure.

    2.3 控件设置(5.png

    Click Event Adding

    Select the Batch Export button, and add a Click event with the following JavaScript code:

    iconNote:
    You can change excel in &format=excel to word or pdf to export files as the corresponding format.
    function ForTime(oldTime) {
    Date.prototype.format = function(fmt) {
     var o = {
      "M+": this.getMonth() + 1,
      "d+": this.getDate(),
      "h+": this.getHours(),
      "m+": this.getMinutes(),
      "s+": this.getSeconds(),
      "q+": Math.floor((this.getMonth() + 3) / 3),
      "S": this.getMilliseconds()
     };
     if (/(y+)/.test(fmt)) {
      fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
     }
     for (var k in o) {
      if (new RegExp("(" + k + ")").test(fmt)) {
       fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
      }
     }
     return fmt;
    }
    var oldTime = (new Date(oldTime)).getTime();
    var curTime = new Date(oldTime).format("yyyy-MM-dd");
    return curTime;
    }

    var url = 'Exporting Multiple Files in Batches Based on Parameters.cpt';
    var name = _g().getParameterContainer().getWidgetByName("Warehouse").getValue();
    var qc = _g().getParameterContainer().getWidgetByName("Opening").getValue();
    var qm = _g().getParameterContainer().getWidgetByName("Closing").getValue();

    var arr = name.split("','");

    for (var i = 0; i < arr.length; i++) {
    var pars = '&format=excel&extype=sheet&__filename__=' + arr[i];
    window.open("${servletURL}?viewlet=" + encodeURI(url + pars) + "&Warehouse=" + encodeURI(arr[i]) + "&Opening=" + encodeURI(ForTime(qc)) + "&Closing=" + encodeURI(ForTime(qm)), "_blank");
    }

    2.4 添加点击事件.png

    Effect Preview

    Save the report. To avoid pagination, click Data Analysis Preview, and the effect is the same as that in the "Expected Effect" section.

    iconNote:
    1. If only one Excel file can be exported from the report, and the code is correct, you need to allow pop-ups in the browser settings.

    2. Internet Explorer is not supported. The effect cannot be previewed on mobile terminals.

    Template Download

    Attachment List


    Theme: Report Application
    • 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