Overview
Version
| Report Server Version | Functional Change |
|---|---|
| 11.0 | / |
11.0.10 | Added support for exporting data to CSV files with a custom encoding format. |
Application Scenario
The new calculation engine helps address the problem of slow loading during template previews, but exporting datasets is relatively slow. In this case, this document provides you with a solution to resolve this problem.
Note:Implementation Method
Slow dataset export is primarily caused by computing all templates before exporting datasets in the templates. Therefore, as long as the new calculation engine supports large dataset export, this problem will be resolved.
By adding a custom button on the toolbar and defining a custom JavaScript event, you can export large datasets with a significantly improved speed.
Note:1. Both CPT and CPTX formats are supported. CPTX templates refer to reports created in FineReport of V10.0 with the new calculation engine enabled.
2. The data to be exported should not exceed 10 million rows x 20 columns, because if the data volume is extremely large, only a portion of the data may be exported.
Example One: FineReport of Versions Before 11.0.10
Custom Button
1. Download and 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 Following Settings: drop-down box, as shown in the following figure.

3. Add a custom button to the toolbar, and click the
icon in Top Toolbar, 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 Preview
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.10 and Later Versions
Custom Button
1. Download and 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
icon in Top Toolbar, 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:
Note:// The name of the datasets to be exported: You can use encodeURIComponent to prevent Chinese characters from garbling.
var dsName = encodeURIComponent("ds1");
//Format of the exported file: The default format is Excel if not specified.
var exportFormat = "csv"
//The encoding type of the exported file: 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 code is used to export 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 Preview
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 code is used 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();