Finereport program network report-Hello, world

Source: Internet
Author: User

 

What is the finereport designer of the program network report? The finereport designer can basically design the vast majority of reports with zero encoding. However, the Report Templates created in this method depend on the designer and report template, some scenarios with special requirements cannot be merged. In this case, you need to design the report by programming and preview it on the J2EE server. The reportlet API finereport API provides a variety of interfaces for users to flexibly design reports. The reportlet API supports program Network reports. Package COM. fr. web; <br/> Import COM. fr. report. reporttemplate; <br/> public abstract interface reportlet {<br/> public abstract reporttemplate createreport (<br/> reportletrequest paramreportletrequest) throws reportletexception; <br/>}The createreport () method returns a report template object for the Report Server to render. You can create a program network report by implementing the reportlet interface and implementing this method. The createreport () method returns a report template object for the Report Server to render. You can create a program network report by implementing the reportlet interface and implementing this method. Hello, world! We will use the programming method to create a red Hello, world in cell A1! Text reports, and preview them on the server. 1. Create a class to implement the reportlet interface. Create a class named helloreport to implement the reportlet interface and implement the createreport method. There is only one method in the reportlet interface. This method returns a reporttemplate instance. Package Fr. report; <br/> Import COM. fr. report. reporttemplate; <br/> Import COM. fr. web. reportlet; <br/> Import COM. fr. web. reportletexception; <br/> Import COM. fr. web. reportletrequest; <br/> public class helloreportlet implements reportlet {<br/> @ override <br/> Public reporttemplate createreport (reportletrequest arg0) <br/> throws reportletexception {<br/> // todo auto-generated method stub <br/> return NULL; <br/>}< br/>}2. Create a reporttemplate instance for the createreport method and return it. 1. Create a worksheet and return it. Com. Fr. Report. reporttemplate is an interface that defines the common behavior of a report template. In this example, we use its implementation class com. Fr. Report. worksheet. A worksheet is used to deploy and beautify a report. It consists of cells with different functions. @ Override <br/> Public reporttemplate createreport (reportletrequest arg0) <br/> throws reportletexception {<br/> worksheet = new worksheet (); </P> <p> return worksheet; <br/>}2. Create a text cell in A1 and add it to the report. The basic behavior that the cell element specified by com. Fr. Report. cellelement should have. Here we use its implementation class com. Fr. Report. defaultcellelement to create a text-type cell. Defaultcellelement (INT column, int row, Java. lang. object value) You can construct a cell with specified coordinates and values to provide different forms and actions for cells based on different parameter value types, creates a text cell. Cellelement cellelem = new defaultcellelement (0, 0, "Hello, world! "); <Br/> worksheet. addcellelement (cellelem );You can also input formula, dscolumn, and other types of construction formulas and data column-type cells. 3. Set a style for the cell. Style settings are cumbersome and need to use the com. Fr. Base. Style Class and COM. Fr. Base. frfont. The method in the official document is as follows. // Create a style <br/> Style = style. getinstance (); <br/> // create a font <br/> frfont = frfont. getinstance ("tahoma", Font. bold | font. italic, 20); <br/> // set the font to Red <br/> frfont = frfont. applyforeground (color. red); <br/> // apply the font to the style <br/> style = style. derivefrfont (frfont); <br/> // apply the style to the cell. <br/> cellelem. setstyle (style );The applyforground () method and the derivefrfont () method are different from the general habits. They modify the object, but return a new object that applies the foreground color (or font. Therefore, you need to assign a value to the reference A = A. doxxx () to ensure the update. In fact, we can use some convenient methods. // Create and apply a style <br/> Style = style. getinstance (frfont. getinstance ("tahoma", <br/> font. bold | font. italic, 20, color. red); <br/> // apply the style to the cell <br/> cellelem. setstyle (style );3. Set the Row Height and column width. Because the Row Height and column width affect the whole row or the whole column, they act as worksheets rather than cells. // Set the Row Height and column width <br/> worksheet. setrowheight (0, 30); <br/> worksheet. setcolumnwidth (0,200 ); Complete code: Package Fr. report; <br/> Import Java. AWT. color; <br/> Import Java. AWT. font; <br/> Import COM. fr. base. frfont; <br/> Import COM. fr. base. style; <br/> Import COM. fr. report. cellelement; <br/> Import COM. fr. report. defaultcellelement; <br/> Import COM. fr. report. reporttemplate; <br/> Import COM. fr. report. worksheet; <br/> Import COM. fr. web. reportlet; <br/> Import COM. fr. web. reportletexception; <br/> Import COM. fr. web. Reportletrequest; <br/>/** <br/> * program network report-Hello, world! <Br/> * http: // localhost: 9527/finereport/reportserver? Reportlet = Fr. report. helloreportlet <br/> * @ author greatghoul <br/> */<br/> public class helloreportlet implements reportlet {<br/> @ override <br/> public reporttemplate createreport (reportletrequest arg0) <br/> throws reportletexception {<br/> // create a Report <br/> worksheet = new worksheet (); </P> <p> // create a cell in A1 <br/> cellelement cellelem = new defaultcellelement (0, 0, "Hello, world! "); </P> <p> // create and apply a style <br/> Style = style. getinstance (frfont. getinstance ("tahoma", <br/> font. bold | font. italic, 20, color. red); <br/> // apply the style to the cell <br/> cellelem. setstyle (style); </P> <p> // set the Row Height and column width <br/> worksheet. setrowheight (0, 30); <br/> worksheet. setcolumnwidth (0,200); </P> <p> // Add a cell to the report. <br/> worksheet. addcellelement (cellelem); </P> <p> return worksheet; <br/>}< br/>}To preview a program's network report, you only need to put the compiled. Class file in the Report Server's classes folder, and then you can access the report through the following URL. Http: // <Report Server address>/reportserver? Reportlet = <implement the fully qualified name of the reportlet class> in this example, the fully qualified name of reportlet is Fr. Report. helloreportlet http: // localhost: 9527/finereport/reportserver? Reportlet = Fr. Report. helloreportlet The effect is as follows:

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.