Execute And Export Template

  • Last update:  2020-12-17
  • I. Introduction

    As we know from the overview of Engine API,  reports can be classified into two categories, that is, the template and the result.

    • The template here refers to workbooks or reports that are not executed, with datasets concluded, data columns unexpanded and formulas not calculated yet.

    • The result comes into being once the execution is performed. At this point, data columns have been expanded in the result, where datasets are no longer stored.

    Please see the diagram below:

    1607072411270091.png

    Once the template receives parameter values, a result will be generated. The rest of the article will illustrate on how to implement this procedure step by step.

    II. Principle

    1. Report Runtime Environment

    The first and foremost thing is to define the environment where the execution happens, so that the database information can be accessed and loaded correctly.

    String envpath = "C:\\FineReport_10.0\\webapps\\webroot\\WEB-INF"; 
    //The project path
    SimpleWork.checkIn(envpath);
    module.start();

    2. Load the Template 

    TemplateWorkBook workbook = TemplateWorkBookIO.readTemplateWorkBook("\\doc\\Primary\\Parameter\\Parameter.cpt");

    3. Inject the Parameter Value 

    /*
    * Define paraMap and inject the parameter from the template as well as its corresponding value, that is, "region" and "Northern China" in this case

    * If the parameter is passed over when the request is being sent, use req.getParameter(name) to acquire it
    * Put the acquired parameter into paraMap.put(paraname,paravalue)
    */
    java.util.Map paraMap = new java.util.HashMap();
    paraMap.put("region", "Northern China");
     // Use paraMap to generate the result  
    ResultWorkBook result = workbook.execute(paraMap, new WriteActor());

    4. Use the Result (Export to Excel)

    For the generated result, users can perform a variety of operations, such as export to Excel or PDF files. Please refer to export API for further information.

    FileOutputStream outputStream = new FileOutputStream(new File(
    "C:\\test\\Parameter.xls"));
    ExcelExporter excelExporter = new ExcelExporter();
    excelExporter.export(outputStream, result)

    III. Instructions

    1. Executable Code

    https://github.com/finereport-overseas/example/blob/release/10.0/src/main/java/com/fr/io/ExcuteDemo.java

    Note: please modify the project path and export path according to your practical situation.

     

    2. Run the Java File

    Running ExcuteDemo.java in the Java IDE will export an Excel file as shown below.

    382.png

    Attachment List


    Theme: Secondary Development
    • 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