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.
Note: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
Note: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:
| Parameter | Example |
|---|---|
(1) When the report contains no parameter: | [{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: |
|
&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.
Note:<!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.

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.
