1.Overview
From the previous section, we get to know that the web report refers to a class that implements the Reportlet interface. It is coded and can be directly visited on the Web browser.
In the previous section, users generate web reports by reading the cpt file. To help users understand the core of web report, in this section, we will introduce how to create web reports.
2. Example
2.1 Create a Report
Create a class CreateReportDemo, which inherits abstract class cpm.fr.web.Reportlet, implements the method createReport(ReportletRequest arg0), and returns a workbook.
// Create a workbook and add a worksheet to it.
WorkBook workbook = new WorkBook();
WorkSheet sheet1 = new WorkSheet();
workbook.addReport(sheet1);
return workbook;
2.2 Insert Cells
From [Basic knowledge], we notice the worksheets consist of cells. Let's insert cells in sheet1, edit cell content and set the cell formats.
Insert a cell with row number 1 and column number 1 ,which is A1. The value can be FineReport:
TemplateCellElement CellA1 = new DefaultTemplateCellElement(0, 0,"FineReport");
Set the cell format, font Arial, bold, size 20 and in red.
Style style = Style.getInstance();
FRFont frfont = FRFont.getInstance("Arial", 1, 20.0F, Color.red);
style = style.deriveFRFont(frfont);
CellA1.setStyle(style);
Set the column width to be 150px, the height of row 0 to be 35 px:
sheet1.setColumnWidth(0, new OLDPIX(150.0F));
sheet1.setRowHeight(1, new OLDPIX(35.0F));
Now a simplest web report is good to use! Check out the link below to get more details:
2.3 Save and Preview
Users need to compile Java source file, save CreateReportletDemo.class to application %FR_HOME%\webapps\webroot\WEB-INF\classes\com\fr\demo, and start up the server. To view the defined web report, simply type in http://localhost:8075/webroot/decision/view/report?viewlet=com.fr.demo.CreateReportletDemo in the browser.