JS Customize Export File Name

  • Last update:  2020-12-23
  • I. Overview

    1.1 Requirement

    FineReport has the built-in export function, but does not support exporting a custom file name. How can we export a custom file name?

    1.gif

     

    1.2 Solution

    Method 1: Modify the title in the Web Attributes interface to export a custom file name (the file name exported by default is the same as the report title).

    Method 2:  Add an event to the Export button and assign the custom file name to be exported as the value of the parameter  __filename__ in the event (note: there are two single underscores before and after filename).

    You will learn
    • Sample

      • Method 1: Modify the title in the Web Attributes interface

      • Method 2: Add an event to the Export button

      • Preview

    • Download the templates

    II. Sample

    2.1 Method 1: Modify the title in the Web Attributes interface

    1) Open %FR_HOME%\webapps\webroot\WEB-INF\reportlets\GettingStarted.cpt

    2) Click [Template]-[Template Parameter] and add date as a template parameter.

    3) Click [Template]-[Web Attributes] and type the title: ${region+"_region_"+date}

     

    4) Modify the title to a dynamic one: $region+"Region Sales Situation"

    5) Edit the parameter pane and delete the Query button.

     

    6) Add a Label widget and set the widget value as date:. Add a Date widget and name it date. Bind the Date widget to the template parameter and set the widget value as Formula. Input the formula TODAY() in the pop-up Formula Definition window.

     

    7) Add an After Editing event respectively to the Drop-down Box widget and the Date widget to make query run automatically:

    Input the following JavaScript codes:

    _g().parameterCommit();

    8)Add a Button widget and name it Export 

    Add a Click event:

     

    Input the following JavaScript codes:

    var REGION = this.options.form.getWidgetByName("region").getValue();
    var DATE = this.options.form.getWidgetByName("date").getValue();
    var REPORT_URL = '${servletURL}?viewlet=GettingStarted1.cpt®ion=' + REGION + '&date=' + DATE + '&format=excel';
    window.location = (FR.cjkEncode(REPORT_URL));

    9)Click the blank area of the parameter pane. Click the Properties tab in the right-hand pane and uncheck [Display Nothing Before Query].

    11.png

     

    2.2 Method 2: Add an event to the Export button

    1) Make modifications on the basis of the steps mentioned in Method 1. Click [Template]-[Web Attributes] and remove the title.

    2) Add a Click event

    Click on the Export Button, add a Click event, and rewrite JavaScript codes:

     

    Input the following JavaScript codes:

    var REGION = this.options.form.getWidgetByName("region").getValue();
    var DATE = this.options.form.getWidgetByName("date").getValue();
    var name = REGION + "_region_" + DATE;
    var REPORT_URL = '${servletURL}?viewlet=GettingStarted2.cpt®ion=' + REGION + '&date=' + DATE + '&format=excel' + '&__filename__=' + name;
    window.location = (FR.cjkEncode(REPORT_URL));


    2.3 Preview

    Save the template and click [Pagination Preview]. The preview effect on a PC is shown as below:

    14.gif 

    III. Download the templates

    1) Method 1:

    GettingStarted1.cpt

     

    2) Method 2:

    GettingStarted2.cpt


    Refer to the original link: https://help.finereport.com/doc-view-1822.html

     

    Attachment List


    Theme: Parameter
    • 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