Ireport uses the database connection JAR file placed in D: \ iReport-4.6.0 \ platform9 \ Lib, rather than D: \ iReport-4.6.0 \ ireport \ libs
1. Installation: the installation of ireport has become very simple since 3.0.0. You only need to download and decompress it, and click the BAT file or EXE file.
If an error is reported, it may be caused by your JDK version or JDK configuration.
2. Required jar packages:
A. To ensure that the results of compiling and generating report files are correct, you must ensure that jasperreports and ireport
For example, jasperreports of 3.0.0 correspond to ireport of 3.0.0.
B. Ensure that the Lib folder of ireport contains the itext-1.1.jar and itextasian. Jar packages which are used
Set the Asian font of the PDF file.
C. For web development, copy the jasperreports-3.0.0.jar file in ireport to the lib directory.
3. Web development:
A. Obtain the JDBC connection: Connection con = (this can be obtained from spring or hibernate and can be directly generated using JDBC ),
B. Fill parameters: parameters are used in database queries or variable titles. The generated Jasper file is used when a specific report file is generated.
You need to assign values to the parameters:
Map props = new hashmap ();
Props. Put ("name", new string ("name "));
C. Manage jasperreports:
Jaspercompilemanager (compile an XML file into a Jasper file)
Jasperfillmanager (fills in the Jasper file or jasperreport to generate the jasperprint object based on parameters and data sources)
Jasperprintmanager (print directly)
Jasperexportmanager (export the jasperprint object as a PDF, xls, and HTML file)-we recommend that you use this for management.
Jasperrunmanager (equivalent to filling jasperfillmanager before exporting jasperexportmanager)
4. Typical Cases
Servletcontext = servletactioncontext. getservletcontext (); // get the server container object
File reportfile = new file (servletcontext. getrealpath ("template/" + jaspername ));
Map parameters = new hashmap ();
Java. SQL. Connection conn = iniconn (); // obtain the database connection
Jasperprint = jasperfillmanager. fillreport (reportfile. getpath (), parameters, Conn );
Jrxlsexporter exporter = new jrxlsexporter (); // create an instance
String endfile = jaspername. substring (0, jaspername. Length ()-7); // export the file path and file name
Exporter. setparameter (jrexporterparameter. jasper_print, jasperprint); // set the Parameter
Exporter. setparameter (jrexporterparameter. output_file_name,
Servletcontext. getrealpath ("/report/Excel") + "/" + endfile + ". xls ");
Exporter. setparameter (jrxlsexporterparameter. is_one_page_per_sheet, Boolean. False );
Exporter. exportreport (); // export the report
Conn. Close ();
5. ireport Design Report considerations:
1. Draw a line. Select this field if you want to draw a line, right-click the field, and choose Properties> border. We recommend that you publish the line on the left and bottom of each field.
Draw online on the left, bottom, and right, so that the two lines won't look repeated.
2. Automatic variables. To add an auto-increment sequence number, you can choose preview> report variable.
Java. Lang. integer, caculation type select count, reset type select report, other default,
After that, drag the variable to your desired location and design it.
3. Automatic line feed. If you do not do this, the content of some fields will be incomplete if it is too long. Select this field, right-click and choose Properties,
In text field, check stretch with overflow. At the same time, select all fields in the row, right-click and choose Properties,
In the common stretch type, select relative to tallest object.
4. quickly organize and align report elements:
. Click any element to be aligned. The corresponding report session will be displayed in the document structure list on the left.
. Use shift to select all elements in the Session (select all elements in batches quickly)
4.3.ctrl + Shift + L, CTRL + Shift + up arrow (left and top alignment will align with the first selected element)
4. Select multiple elements at the same time and click "modify attributes in batches.
5. Report Group:
. To ensure that your report data is printed one by one according to a certain rule, you need to group the reports. A typical one-to-many relationship is output.
. The relationship between A and B is one-to-many. We hope to output the personnel information according to the department;
5.3.select department. Name department. ID employee. Name employee. Message from department, employee where employee. Department ID = Department. ID
5. 4. select Edit Group-> Create report group wizard-> enter the name, select report object from result properties-> two next
5. In grouphead, pull the group header you want to display. The group members in the loop are displayed in the middle. groupfoot displays the bottom information of the report.
. Run ireport to get the desired result.
6. General operations:
6.1.ireport3.0.0 can be copied and cut during design, which is prone to errors. It is not recommended when designing reports.
. Select the sequence expression, category expression (category name), and numeric expression (used to generate a chart and can only be a number) for displaying data in a chart)
. Use Database Connection in the subreport table: $ P {report_connection}. This parameter records
Java. SQL. Connection objects can be directly used in subreports to establish database connection and query.
Problems encountered during ireport report development:
1.In the toolbar of the report
T: No text
F: text fields passed by the program
2.Preview The report content on the web page.
Solution:
Edit-> report properties-> more...-> "If no data exists, select all sections and no detail from the drop-down menu"
If there is no data, the following drop-down menu options mean:
No pages [no page display when there is no data in detail]
Blank Page [a blank page appears when there is no data in detail]
All sections, no detail [display items other than detail when there is no data in detail]
No-date section [] I don't know either.
3.There is always a blank space between detail and columnfooter.
Solution: Set [Preview]-> [report attributes] From the ireprot tool column.
Open [more...]-> [floating column footer] And check columnfooter to be associated with detail.
4.Display format of the detail loop content in the report
The display format of the detail loop in a report depends on the bottom boundary of the report attribute> page margin>.
For example, there are two columns in detail. When the data fills up the first column, [based on the size of the detail Page]
The data will be automatically filled in the second column. [the size of the detail page determines when the first column will be filled with Data]
When multiple data entries are filled in detail, they are filled by the size left for the displayed data on the page.
Determine the number of rows of data displayed based on the number of data entries displayed on the page.
Controls displayed by condition still occupy the page position when they are not displayed.
5.Common tab in text box:
Print when exprIn the ession attribute, the boolean type indicates whether the field is displayed or not. The content is generally:
New Boolean (the result is a boolbean expression)
6.In the text box, the font tab font can be correctly displayed only when the font is set:
[1]Font Name: Select
PDF Font Name: Select stsong-light
Final PDF encoding: Select UniGB-UCS2-H (Chinese Simplified)
[2]Reference external fonts, such as external Fonts
Place the font file in the fonts folder in the ireport installation directory, such as the inventory book [D: \ iReport-3.0.0 \ fonts \ simli. TTF]
Font Name: select the answer book
PDF Font Name: select External font file example (simli. TTF)
Final PDF encoding: Select Identity-H (UNICODE with horizontal writing) [select it for all external files]
7.Text Field tab in the dynamic text box:
A [check box blank when null] indicates whether to display null when the content of this text box is empty.
When it is indicated as null on the hook, the blank display will look better. If it is not checked, the null display will be better.
8.$ V {page_count} indicates the number of records on this page [used in the detail loop-related area]
$ V {page_number} indicates the current page
$ V {column_number} indicates the number of detail fields
9.The field is the number of columns in the tool-> report properties-> field quantity settings.
The number of fields separates detail into the corresponding columns. When the first column on the page is not displayed, it will automatically jump to the second column on the page, and so on.
10.Data Conversion Type in the report:
In the $ V {page_count}. intvalue () Report, convert the value of V to int.
Integer. valueof ($ P {pagecount}). In the intvalue () Report, convert the P attribute to int.
Double. valueof ($ f {realsum })Convert F type to double type in report
($ V {realsums}. doublue () + $ V {realsumms}. doublue () Double Type sum
Boolean. valueof (list) $ f {mentalstate}). Contains ("02") convert Boolean value to boolbean
11.Operations on data in the report:
When adding a text box: the plus sign must be of the numerical type. If not, the plus sign becomes a join instead of an addition operation.
($ V {realsums }! = NULL? $ V {realsums}: Double. valueof (0). doublue ()
+
($ V {realsumms }! = NULL? $ V {realsumms}: Double. valueof (0). doublue () + "Yuan"
12.Some methods used in the report:
Contains () method :( (list) $ f {mentalstate}). Contains ("02") from list type mentalstate find 02 return Boolean Value
Equals () method: used for comparison between two string types
The value of the valueof () method must be of the string type. Otherwise, an error will be reported during compilation.
13. Description of report region structure:
Title Report header [only displayed at the top of the first page]
Pageheader header [displayed on each page]
Columnhearder [similar to columnfooter, columnhearder shown before detail]
Detail [write the items that need to be displayed cyclically]
Columnfooter [displayed below the loop] current record with a loop of $ V {page_count}
The end of the pagefooter report [at the bottom of the last page]
Summary [This is used for statistics. It is of little use if it is displayed]