Common problems of Jasper+ireport development report system!

ireport uses database connection jar files placed in D:\iReport-4.6.0\platform9\lib instead of 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 unzip it, click the bat file or exe file

   , if an error is reported, it may be a problem with your JDK version or JDK configuration.

 

2. The required jar package:

                      a. In order to ensure that the compiled and generated report files are correct, you need to ensure that JasperReports and iReport

                          The version is consistent, for example, JasperReports 3.0.0 corresponds to iReport 3.0.0

                       b. Make sure that the lib folder of iReport contains two packages, itext-1.1.jar and iTextAsian.jar, which are used for

                         Sets the Asian font for PDF files.

                       c. When doing web development, copy the jasperreports-3.0.0.jar file in iReport to the lib directory.

 

3.Web development:

                   a. Obtain JDBC connection: Connection con = (here can be obtained from spring or hibernate , or directly generated by JDBC),

                   b. Filling parameters: parameters are used in database queries or variable titles, and the generated Jasper files are generated when specific report files are generated

                      You need to assign values ​​to the parameters:

                      Map props = new HashMap();

                      props.put("name", new String("name")); 

                   c. Manage JasperReports:

                    JasperCompileManager (compile xml files into jasper files)

                    JasperFillManager (fill jasper file or JasperReport according to parameters and data source to generate JasperPrint object)

                    JasperPrintManager (direct output for printing)

                    JasperExportManager (exports JasperPrint objects to PDF or XLS, Html files)----It is recommended to use this for management

                    JasperRunManager (equivalent to filling the JasperFillManager first, and then exporting the JasperExportManager)

4. Typical case

  ServletContext servletContext =ServletActionContext.getServletContext();//Get server container object
  File reportFile = new File(servletContext.getRealPath("Template/"+jaspername));
  Map parameters = new HashMap();
  Java .sql.Connection conn =iniconn ();//Get database connection
  JasperPrint jasperPrint=JasperFillManager.fillReport(reportFile.getPath(),parameters,conn);
  JRXlsExporter exporter = new JRXlsExporter();//Create instance
  String endfile=jaspername.substring(0, jaspername.length ()-7);//Export file path and file name
  exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);//Set parameters
  exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME,

                                      servletContext.getRealPath("/Report/Excel")+"/"+endfile+".xls");
  exporter.setParameter(JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.FALSE);
  exporter.exportReport();//导出报表
  conn.close();

5. Notes for iReport design report:

   1. Draw lines. If you need to draw a line, select the field, right-click -> Properties -> Border, it is recommended to draw lines on the left and bottom of each field, and the last field is

                   Draw lines on the left, bottom, and right sides so that the lines don't appear to be duplicated.
   2. Automatic variables. If you need to add an automatically incremented serial number, you can choose a name and variable type in Preview -> Report Variables

                     java.lang.Integer, select Count for Caculation type, select Report for Reset type, and default for the rest.

                     After finishing, drag and drop the variable to the position you like and design it.
   3. Automatic line wrapping. If you don't deal with it, the content of some fields will be too long and will not be displayed completely. Select the field, right click -> Properties,

                     Check Stretch with overflow in Text Field. At the same time, select all fields in the row, right-click -> Properties,

                     Select Relative to tallest object in Common's Stretch Type.

   4. Quickly organize and align report elements:
      4.1. Click on any element to be aligned, and the corresponding report session in the document structure list on the left will open
      4.2. Use the shift key to select all elements in the session (quick batch selection of all elements)
      4.3.ctrl+shift+l, ctrl+shift+up arrow (align left and top, both will be aligned with the first selected element)
      4.4. Select multiple elements at the same time and then click the attribute to modify in batches.

   5. Report grouping:

      5.1. In order to ensure that your report data is printed out one by one according to a certain rule, you need to group the reports, typically with one-to-many relationship output.

      5.2. The relationship between A and B is one-to-many, and we hope to output personnel information by department;

      5.3.select department.name department.ID employee.name employee.message from department,employee where employee.department ID=department.ID

      5.4. Select Group Edit->New Report Group Wizard->Fill in the name, select the report object from the result property->next twice

      5.5. Pull in the group header you want to display in the grouphead, the group member part of the loop is displayed in the middle, and the groupfoot displays the bottom information of the report.

      5.6. Run iReport to get the result you want.

  6. General operation:
      6.1.iReport3.0.0 can be copied and cut during design, which is easy to make mistakes, so it is not recommended to use it when actually designing reports.

      6.2. Selection of data displayed by the chart: sequence expression (how many), category expression (category name), numerical expression (for generating charts, only numbers)
      6.3. Use database connection in subreports: $P {REPORT_CONNECTION}, this parameter records this one relative to this report

            The object of java.sql.Connection, which can be directly used in sub-reports to establish database connection and query.

 

Problems encountered in iReport report development:

1. T in the toolbar of the report
: will not become text
F: text field passed from the program

2. Preview the report on the web page and nothing is displayed.
Solution:
Edit->Report Properties->More...->In "If there is no data: select All sections, no detail in the drop-down menu behind"
If there is no data: behind The meaning of several options in the drop-down menu are:
No pages [when there is no data in Detail]
Blank page [when there is no data in Detail] A blank page appears]
All sections, no detail [when there is no data in Detail] The data will show things other than detail]
No-date section [] I don't know for the time being, huh, huh.

3. There is always a blank space between Detail and columnFooter
Solution: From iReprot Toolbar Settings [Preview] -> [Report Properties]
, open [More...] -> [Floating column footer] If you check the columnFooter, it will be in the same position as Detail. together.

4. The display format of the content of the
Detail loop in the report The display format of the content of the Detail loop in the report is related to the size of the report properties -> Page Margin -> lower border

For example, there are two columns in the detail. When the first column is filled with data [according to the detail page size] , the
data will be automatically filled into the second column [the detail page size can determine when the first column can be filled with data]

When multiple pieces of data are filled in Detail, they are filled according to the size reserved for the displayed data on the page. When
controlling how many rows of data are displayed, the judgment is made strictly according to how many pieces of data can be displayed on the page
. The controls displayed according to the conditions still occupy when they are not displayed. page location.

5. Common tab in the text box:
Print when expression property is of Boolean type, indicating whether the field is displayed or not. The content is generally:
new Boolean (the result is an expression of boolbean type)


6. The font selection of the Font tab in the text box is a complete set to display correctly:
[1] Font Name: select Song
Dynasty PDF Font Name: select STSong-Light
Last PDF Encoding: select UniGB-UCS2-H (Chinese Simplified)
[2] Refer to external Fonts such as official script
Put the font file in the fonts folder of the iReport installation directory, such as official script [D:\iReport-3.0.0\fonts\SIMLI.TTF]
Font Name: select official script
PDF Font Name: select external font file official script (SIMLI .TTF)
Last PDF Encoding: select Identity-H (Unicode with horizontal writing) [select it for external files]

7. The Text Field tab in the dynamic text box:
there is a [checkbox Blank when null] in the middle, indicating whether to display null when the content of this text box is empty.
It will be better to display blank when the hook is represented as null, and it will be better to display null if it is not hooked.

8. $V{PAGE_COUNT} indicates the current record of this page [used in the detail loop related area]
$V{PAGE_NUMBER} indicates the current page
$V{COLUMN_NUMBER} indicates how many fields in the detail

9. The number of fields, that is, the number of columns, is set in the tool Edit->Report Properties->Number of Fields.
The number of fields divides the detail into these corresponding columns. When the first column on a page cannot be displayed, it will automatically jump to the second column of this page and so on.

10. Data conversion type in the report:
$V{PAGE_COUNT}.intValue() The V property in the report is converted to int
Integer.valueOf($P{pageCount}).intValue() The P property in the report is converted to int
Double.valueOf($F{ realSum}) The F type in the report is converted to Double
($V{realSums}.doublue()+$V{realSumMs}.doublue()) The double type is added and summed
Boolean.valueOf(((List)$F{mentalState} ).contains("02")) converts boolean value to Boolbean

11. Operation of the data in the report:
When adding operation in the text box: The plus sign must be of numeric type. If not, the plus sign becomes a connection function instead of an addition operation.
(($V{realSums}!=null?$V{realSums}:Double.valueOf(0)).doublue()
+
($V{realSumMs}!=null?$V{realSums}:Double.valueOf(0 )).doublue())+" yuan"

12. Some methods used in the report:
contains() method: ((List)$F{mentalState}).contains("02") Find 02 in mentalState of List type and return boolean value
equals() method: used for two Comparisons between
String types

13. Report area structure description:
title report header [only displayed at the top of the first page]
pageHeader page header [every page will display]
columnHearder [similar to columnFooter, columnHearder is displayed before detail]
detail [things that need to be displayed cyclically are in Write here]
columnFooter [displayed below the loop display] $V{PAGE_COUNT} with loop current record
pageFooter end of the report [displayed at the bottom of the last page]
summary [this is used for statistics, it is not very useful to display]

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326801986&siteId=291194637