JASPERREPORTS and IREPORT for use (finishing)

xiaoxiao2021-03-06  74

JasperReports and IREPORT

2 download

Ireport-

0.4.0

(Report visual editing tool)

ITextasian.jar joins ClassPath if it contains Asian characters in the report to output a PDF file.

2 Use of Ireport

1. Select New Report on the Toolbar, set basic information, including name, print paper size, print direction (longitudinal or horizontal), select XML encoding mode in the More tab, if you need XML support Chinese, then XML encoding is GB2312, You can also choose the total title and summary to print separately.

2, the main elements on the report are static text, variable, dynamic domain (Field), parameter. Static text is a text that is constant on the report. Variables refer to some values ​​obtained by computing through the system (such as current pages, total record number, etc.). The dynamic domain can be the field when connecting the database, or can be a custom data source (which may be a physical class containing a set of data). The parameters are variables transmitted within the report to the report, usually in the form of the MAP, can be used as a display variable or a condition for change in the SQL statement.

Note: $ P {param_name} represents the parameter, {} is the name of the parameter. After setting in the report, the title and other data are dynamically generated by the parameters incorporated from the outside, and can be introduced as a query condition. SQL statement use (if you use JDBC directly to connect to the database)

$ V {page_number} Represents the current page, $ V represents Variable, for existing group, $ v {groupname_count} represents the number of records of the current group

The $ f {field_name} represents the field and is the most important part of the report. If the JDBC method is connected, enter the SQL query statement to get the fields obtained by all queries; if it is a Custom Datasource method, create a new field, such as user_id. GetfieldValue (JRFIELD FIELD) in the data class is the $ f {field_name} in the report. Which value returned according to the Name property of the JRField object in the program

// Representative Returns the fourth field of the current line

IF ("User_ID" .Equals (Field.getName ())) Return Data [INDEX] [3];

3. After dragging the above elements to the report page, you need to set their font fontname to use the font used when previewing the IREPORT, and if you might contain Chinese, you must select a Chinese font, otherwise it will not be displayed normally. PDF Font Name Selects STSONG_Light, hook on the PDF Embeded PDF Encoding check box, and select unigb_ucs2_h (Chinese_SIMPLified) in the drop-down box. The PDF file that is output can be displayed normally.

Note: If you generate a Chinese report with Ireport, you need to copy itextasian.jar to the lib folder of Ireport.

Select the text domain in the TextField tab, reselect the evaction time as NOW (if you do not activate the drop-down box, the evaction time error word will appear when running). If text is in a group, select the corresponding group from the Evaluation Group. Check the Blank When Null. TextField Expression is the expression of the text that can do some simple operations such as string connections, such as "current page" $ V {page_number}. Pattern Click the Create button to select the formatted form of the time date, which is convenient for dynamic generation of report printing time. 4. Select a variety of ways in the Build menu. The default is to preview the display in Ireport after compilation. Select PDF Preview is the output as a PDF file to preview the display effect. In actual web printing, PDF is generated using the method provided by JasePerReport.

5, several ways of DataSource

a) JDBC connection database. Create a new connection, select the type of Database JDBC Connection, connect to this connection, fill in the URL of the Driver, Database Connection, the database username, etc., the test can be established.

b) Customer JRDataSource acquire data. First write a class containing data, it implements the JRDataSource interface to implement both methods of NEXT () and GetFieldValue (JRFEild Field). Next method is used to obtain the next record, the GetFieldValue method obtains the corresponding column data according to the name of the Field defined in the Jasper file. In addition, in order to preview the effect in IREPORT, we also need to construct a method of obtaining the data source class, typically named the XXXDataSourceFactory class, which provides the GetThedASource class to get the data source class. When connected, the data can be obtained after filling the factory class and obtaining the corresponding method of obtaining the data source.

Then the build-> set Active Connection on the menu select the connection, enter the SQL statement or JavaBean mode to get the data field in DataSource-> Report Query. The obtained data field is placed in the field in the field, which can be dragged to the page report.

6, the compilation process is to compile the * .jrxml file into the * .jasper file that JasperReport can use. We only need to get a Jasper file from Ireport.

2 Web print procedure

1. First, the class of data to be taken, the method of forming an object array can be obtained by JDBC or other means.

Public DataSource Implements JrdataSource {

Private object [] [] data = {};

Public void next () {

// Acquired an object array next line

}

Public Object GetfieldValue (Jrfield Field) {

// Character string of the name of the domain and return the corresponding value

}

}

2. Method for generating PDF in JasperReport

JasperrunManager.RunreportTopdffile

String Arg, String Output, Map Param, JRDataSource DataSource

// arg indicates the Jasper file directory used by the report, but the output refers to the path and file name of the PDF file, and the PARAM refers to the MAP of the parameters that need to be used in the report, DataSource is the entity class containing the data.

转载请注明原文地址:https://www.9cbs.com/read-88769.html

New Post(0)