JAPERTREPORTS & IREPORT open source report actual combat

xiaoxiao2021-03-06  44

JasperReports Ireports, the open source report system similar to CrystalReport, is most important to help us separate data and representation when designing, helping us to implement the page printing of web reports, packets, and defective and subtraction, and output formatting, There are exported Excel, PDF, etc.

Google has entry tutorials, which is very easy. But in a complex statement, the entry will not be turned quickly. If there is no intermediate study, it may have to go back to the HTML pictorial.

First, there is a JasperReport toll document on the Internet, but honestly say that this document is charged too thin.

1. Customize the data source, incorporate the VO array without querying SQL in JasperReports.

1.1 Why do you have a simple data source that you don't need to customize the data source, you can write SQL directly in JasperReports. However, when the query is complicated, it will still be able to make SQL writing will make SQL and difficult to read, and it has never hate others on SQL. At this time, data is collected in the Java program outside the JasperReport (you can further package similar queries into a data acquisition class), incorporate the results through custom data source into JasperReports, while JasperReport is only responsible for data display, More in line with data and display this unique mode. After getting the data source that can be decomposable, I really dare to use JasperReports to use the system. Otherwise, you can't imagine how to maintain so many SQL in the JasperReport file.

1.2 Customized data source mechanism DORI.JASPER.EENGINE.JRDataSource interface is very simple, as long as two methods are implemented:

Public Boolean next () throws jrexception; public object getfieldValue (JRFIELD JRFIELD) THROWS JREXCEPTION;

Look at the function name knows its meaning. Fortunately, we even have two ways, Jaspert has two Vo Beans's default implementation. They are dori.jasper.Engine.Data.jrbeanarrayDataSource and Dori.jasper.Engine.Data.jrbeancollectionDataSource. Look at the name, I can use Array to put bean, one with collection.

Unfortunately, if VO has an embedded object, you cannot read the syntax of $ f {order.customer.name}.

Hibernate's HQL query results are also supported. Have a compromise, but it is not good.

1.3 Sample Code and Explanation

/ / Encaps the REPORTER MoonCakeReporter MooncakeReporter (); // to establish a Vo's MAP, because you need to perform a query multiple times, you need to quickly retrieve VO to assign a value, so use map.map map = new hashmap () ; rs = mooncakeReporter.findAllVaildProduct (); while (rs.next ()) {MooncakeVO mooncakeVO = new MooncakeVO (); String goods_no = rs.getString ( "goods_no"); String goods_name = rs.getString ( "name"); Mooncakevo.setname (Goods_Name); MoonCakevo.setCode (Code); map.put (goods_no, mooncakevo);} // call the Reporter packaged query function to obtain data, and get VO by primary key goods_no to assign values. rs = mooncakeReporter.findSaleOrderByShopType ( "shop"); while (rs.next ()) {String goods_no = rs.getString ( "goods_no"); MooncakeVO mooncakeVO = (MooncakeVO) map.get (goods_no); if (mooncakeVO =! NULL) {mooncakevo.setshopcount (NEW ITEGER ("count"))))))))))))))))))))))))))))));}} // Some steps are repeatedly executed ..... // Because JrbeancollectionDataSource needs collection or array, convert MAP to LIST . List result = new arraylist (map.values ​​()); // Sort RESULT, implemented by beanutils's beancomparator, will be said in the next section. Collections.sort (result, new BeanComparator ( "code")); // finally result assigned JRBeanCollectionDataSourceJasperPrint jasperPrint = JasperFillManager.fillReport (jasperReport, parameters, new JRBeanCollectionDataSource (result)); 1.4 1. extended for sorting map with BeanComparator The VO to store is no order, must be sorted. With Jakata Commons-Beanutils's BeanComparator class, you can dynamically change the columns, which is better than your own Compare () interface.

Collections.Sort (Result, New BeanComparator ("CODE")); for "ORDER BY Lastname, Firstname", you can also write this, where ComparatorChain belongs to the Jakata Commons-Collections package.

ArrayList sortFields = new ArrayList (); sortFields.add (new BeanComparator ( "lastName")); sortFields.add (new BeanComparator ( "firstName")); ComparatorChain multiSort = new ComparatorChain (sortFields); Collections.sort (rows, multiSort ); 2. element, finally do not have a hand-plan line.

Ireports finally came from 0.41, support JasperReports 0.64.

Why is this important? Because JasperReports supported the Box properties of the thousand calls from 0.63, JasperReports allows you to set the four weeks of the table in other business report tools. And before, although everyone said that fairy is good, I think of a form line, but also exactly staying 1 pixel between the two fields, the scalp is a burst of numbness.

In addition, the new BOX is also good under Excel, no longer need to make two different template files for HTML and Excel.

3. The quick design of the aireport report does not understand, facing the full screen element, the drag half is aligned, almost can't use it.

3

.1 Quickly organize, the elements within the relevant table are the faster ways to demonstrate:

1. Click the elements you want to align, the corresponding session in the list of documents on the left will open

2. Use the Shift key to select all the elements in the session

3.ctrl shift l, Ctrl Shift up arrow

It turns out that there is a messy element.

After adding or deleting an element in the report, use this method quickly reorganizes the page.

The first and second step is to select all the elements for fast batch, you can also select it with a mouse, or press the Shift key to select one.

Step 3 is to align the left alignment and upper alignment, and will be in line with the first elements.

3.2 Batch modification Element Properties Like a lot of web editors, you can select multiple elements at the same time then select the property batch modification.

3.3 IREPORT, UltraEdit Dual Dual Double Tunnel This variable variable variables When the variable is more than, using UltraEdit directly Copy Paste is more faster than using Ireport and Varible is a lot.

4. Export an Excel file

The Excel file that started to be exported was incomparably disappointed, and an Excel file that gave out should be at least: 1. All Field wants to stand the height of the BAND, do not leave a gap 2. All objects are selected transparent transparent 3. Setting parameters

Exporter.SetParameter.is_remove_empty_space_betWeen_Rows, Boolean.true; Exporter.SetParameter.is_white_porterparameter.is_white_page_background, boolean.false;

5. JasperReports Some supplements

5.1 Output GBK Character Set

Exporter.SetParameter (JrexporterParameter.Character_Encoding, "GBK"); 5

.2 Define the Pattern displayed by FileD

For example, after the number of small numbers, financial count (one, numbers), etc., if the Pattern provided by Ireport is not cool, you can also directly change the XML file 5.3 Expresstion uses a three-purpose operator to achieve simple IF-ELSE to choose some cases such as The denominator cannot be determined by 0, and it can be done with a three-mean operator. Don't be able to work with VO. 5.4 Batch Compile Document Ireport's Plug-in bulk in batches of all files in all files in Jiangnan white

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

New Post(0)