Summary ireport can display charts, pie charts, and graphs, or display reports
Jasperreports introduction:
Using jasperreports to generate a report is very simple. You can use only several classes in the net. SF. jasperreports. Engine package to generate, preview, print, and export a report.
1. net. SF. jasperreports. Engine. jaspercompilemanager class.
You can use several static methods of this class to compile the report (For details, refer to the API documentation)
After compilation, jaspercompilemanager can be processed in two ways:
1> return a jasperreport object
2> Generate a. Jasper file in the directory where the. jrxml file is located.
The two methods are selected by the programmer. However, I prefer to use the. Jasper file. After all, the report structure is not changed every day, so it is not very cost-effective to recompile the report every time.
2. net. SF. jasperreports. Engine. jasperfillmanager class
This class is used to fill the report with data. It can also use the jasperreport object. The Jasper file is used as a report template.
It also has two processing methods:
1> return a jsaperprint object.
2> Generate a. jrprint file in the directory where the. Jasper file is located.
This class uses the net. SF. jasperreports. Engine. jrdatasource interface as the data source. Any class that implements jrdatasource can be used as a data source.
Some data sources are defined in the net. SF. jasperreports. Engine. Data Package and can be selected as needed. Here I use jrtablemodeldatasource
Data Source (because my reports are also displayed in the table ).
3. net. SF. jasperreports. Engine. jasperprintmanager and net. SF. jasperreports. Engine. jasperexportmanager
The two types are used to print and export reports.
They use the jasperprint and. jrprint files as input.
You can use the method as needed.
Example:
Import net. SF. jasperreports. Engine .*;
Import net. SF. jasperreports. View .*;
Public class compilereport {
Public static void main (string ARGs []) {
Try {
// Compile report. jrxml and generate the report. Jasper file in the directory where report. jrxml is located.
Jaspercompilemanager. compilereporttofile ("report. jrxml ");
// Fill in the Data. jremptydatasource is used here.
Jasperfillmanager. fillreporttofile ("report. Jasper", null, new jremptydatasource (50 ));
// Preview the report. False indicates that the XML file is not used.
Jasperviewer view = new jasperviewer ("reports. jrprint", false );
View. Pack ();
View. setvisible (true );
}
Catch (exception e ){
E. printstacktrace ()
}
}
}
Although the jasperprintmanager class can be exported as PDF and XML files, the jasperprintmanager class is not recommended. We recommend that you use the jasperexportmanager class to export PDF, HTML, and XML files. You need to export XLS and CSV files, use a professional export class. net. SF. jasperreports. engine. export. jrxlsexporter class and net. SF. jasperreports. engine. export. jrcsvexporter class
Code segment exported as XLS:
Jrxlsexporter exporter = new jrxlsexporter (); // create an instance
// Design Parameters
Exporter. setparameter (jrexporterparameter. jasper_print, jasperprint );
Exporter. setparameter (jrexporterparameter. output_file_name, strdestfile );
Exporter. setparameter (jrxlsexporterparameter. is_one_page_per_sheet, Boolean. False );
Exporter. exportreport (); // Export
The exported CSV file is similar to the xls file.