Overview
Version
| Report Server Version | Functional Change |
|---|---|
| 11.0 | / |
11.0.10 | Added support for exporting CSV files with a custom encoding format via the CSV Export Encoding plugin. |
Application Scenario
The new calculation engine helps address the issue of slow loading during template previews, but the problem of slow exporting remains. In this case, this document provides you with a solution to resolve this problem.
Note:Implementation Method
The slow exporting speed is primarily caused by the need to compute all templates before exporting. Therefore, as long as the new engine supports large dataset export, this issue will be resolved.
By adding a custom button on the toolbar and defining a custom JavaScript event, you can export large datasets with the exporting speed significantly improved.
Note:1. Both CPT and CPTX formats are supported. CPTX templates refer to reports created in the FineReport of V10.0 with the new calculation engine enabled.
2. The exported data should not exceed 10 million rows by 20 columns, because exporting excessively large datasets may result in only part of the data being exported.
Example One: FineReport of Versions Before 11.0.10
Custom Button
1. Open the template Row-based Report.cpt. New Calculation Engine is enabled in this template. For details, see Usage Instruction to the New Calculation Engine.
2. Choose Template > Web Attribute > Pagination Preview Setting, and select Set for This Template Separately from the drop-down list of Following Settings, as shown in the following figure.

3. Add a custom button to the toolbar, and click the top toolbar editing button, as shown in the following figure.

4. Set Widget Alias of the custom button to Large Dataset Export, and click Custom Event, as shown in the following figure.

5. In the Set Callback Function window, enter the JavaScript code, as shown in the following figure.

The JavaScript code is as follows:
// The name of the datasets to be exported: You can use encodeURIComponent to prevent Chinese characters from garbling.
var dsName = encodeURIComponent("ds1");
// The server address: The IP address, port number, and web application name should be adjusted according to the actual situation.
var url = "http://localhost:8075/webroot/decision/url/report/v10/direct/export" + "?sessionID=" + Report.SessionMgr.get() + "&dsName=" + dsName;
// The following section is for exporting the dataset as a form.
var form = $("<form>");
$("body").append(form);
if (url.indexOf('?') !== -1) {
var q = url.substr(url.indexOf('?') + 1);
var qs = q.split('&');
for (var i = 0; i < qs.length; i++) {
var p = qs[i];
var ps = p.split('=');
if (ps.length === 2) {
$('<input/>').attr('name', ps[0]).val(ps[1]).appendTo(form);
}
}
url = url.substring(0, url.indexOf('?'));
} else {
var input = $("<input>");
form.append(input);
}
form.attr({"style": "display : none", "target": "", "method": "post", "action": url});
form.submit();
form.remove();Effect Display
Save the report and click Pagination Preview. The following figure shows the preview effect.

Template Download
For details, you can download the template: Large Dataset Export with the New Calculation Engine Enabled.cpt
Example Two: FineReport V11.0.20 and later versions
Custom Button
1. Open the template Row-based Report.cpt. New Calculation Engine is enabled in this template. For details, see Usage Instruction to the New Calculation Engine.
2. Choose Template > Web Attribute > Pagination Preview Setting, and select Set for This Template Separately from the drop-down list of Following Settings, as shown in the following figure.

3. Add a custom button to the toolbar, and click the top toolbar editing button, as shown in the following figure.

4. Set Widget Alias of the custom button to Large Dataset Export, and click Custom Event, as shown in the following figure.

5. In the Set Callback Function window, and enter the JavaScript code, as shown in the following figure.

The JavaScript code is as follows:
Note:// The name of the datasets to be exported: You can use encodeURIComponent to prevent Chinese characters from garbling.
var dsName = encodeURIComponent("ds1");
//The exporting format: The default format is Excel if not specified.
var exportFormat = "csv"
//The exporting encoding type: This setting is only effective when the export format is CSV.
var encodeFormat = "UTF - 8"
// The server address: The IP address, port number, and web application name should be adjusted according to the actual situation.
var url = "http://localhost:8075/webroot/decision/url/report/v10/direct/export" + "?sessionID=" + Report.SessionMgr.get() + "&dsName=" + dsName + "&exportFormat=" + exportFormat + "&encodeFormat=" + encodeFormat ;
// The following section is for exporting the dataset as a form.
var form = $("<form>");
$("body").append(form);
if (url.indexOf('?') !== -1) {
var q = url.substr(url.indexOf('?') + 1);
var qs = q.split('&');
for (var i = 0; i < qs.length; i++) {
var p = qs[i];
var ps = p.split('=');
if (ps.length === 2) {
$('<input/>').attr('name', ps[0]).val(ps[1]).appendTo(form);
}
}
url = url.substring(0, url.indexOf('?'));
} else {
var input = $("<input>");
form.append(input);
}
form.attr({"style": "display : none", "target": "", "method": "post", "action": url});
form.submit();
form.remove();Effect Display
Save the report and click Pagination Preview. The following figure shows the effect.

Template Download
For details, you can download the template: Large Dataset Export with the New Calculation Engine Enabled - Example Two.cpt
Other Description
Export with Parameters
For details, you can download the template: Parameter Linkage in Drop-down Box Widgets.cpt
If you want to export templates with parameters, you can filter parameters on the parameter panel. For details about specific settings, see Parameter Linkage Among Drop-down Boxes by SQL Statements.
The settings of the custom button are shown in the following figure.

Other steps are the same as in the section "Example One: FineReport of Versions Before 11.0.10". The JavaScript code is as follows:
// The name of the datasets to be exported: You can use encodeURIComponent to prevent Chinese characters from garbling.
var dsName = encodeURIComponent("ds1");
// The server address: The IP address, port number, and web application name should be adjusted according to the actual situation.
var url = "http://localhost:8075/webroot/decision/url/report/v10/direct/export" + "?sessionID=" + Report.SessionMgr.get() + "&dsName=" + dsName + "&area=" + a + "&province=" + b + "&city=" + c ;
// The following section is for exporting the dataset as a form.
var form = $("<form>");
$("body").append(form);
if (url.indexOf('?') !== -1) {
var q = url.substr(url.indexOf('?') + 1);
var qs = q.split('&');
for (var i = 0; i < qs.length; i++) {
var p = qs[i];
var ps = p.split('=');
if (ps.length === 2) {
$('<input/>').attr('name', ps[0]).val(ps[1]).appendTo(form);
}
}
url = url.substring(0, url.indexOf('?'));
} else {
var input = $("<input>");
form.append(input);
}
form.attr({"style": "display : none", "target": "", "method": "post", "action": url});
form.submit();
form.remove();