I. Description
FineReport supports the export of reports in various formats, and reports can be exported to other formats very quickly and conveniently by directly using the built-in export button of FineReport. But sometimes we need to customize the exported file type. So how to customize the exported file type?
You will learn |
---|
|
II. Ideas
This can be achieved by adding custom buttons to the Pagination Preview Settings to set JS events.
III. Implementation steps
3.1 Template settings
Let's take the customization of exported txt file as an example.
Open the template: %FR_HOME%\webapps\webroot\WEB-INF\reportlets\GettingStartedEN.cpt
Click template > Template Web Attributes > Pagination Preview Settings > Setting for Template Separately, as shown below:
Double-click the Custom button to set the widget alias to “Custom”, as shown below:
3.2 Define events
Click Custom Event to enter the interface of setting callback function
Add two parameters servletURL and reportName, and insert the formulas for the parameter values: servletURL and reportName, as shown below:
JS code:
var mrname=FR.cjkEncode(reportName); /* directory and file name, encoded by fanruan js*/
var mrurl=servletURL+'?viewlet='+mrname; /* get the path*/
/*window.open(mrurl+'&format=text');*/
window.location.href=mrurl+'&format=text';/*download the file*/
Note: The final exported file type is determined by the content of format=text in the JS code
The export code is as shown above:
format=word // Export a file in Word format
format=excel //Export a file in Excel format
format=pdf //Export a file in Excel format
IV. Preview
4.1 PC terminal
Click the Pagination Preview and click the Custom button on the toolbar to export a txt file, as shown below:
Note: Mobile terminal is not supported.