1. Overview
A cell is the smallest element that forms a report. FineReport opens many attributes of cells to application developers, such as inserting cells, setting column width, row height, font, foreground color, background color, display position, border style, Border color and so on.
Below we will demonstrate an example to list the common attribute settings for reference.
2. Example
To change the format of a cell, you should first obtain the Style of the CellElement. If you are creating a new cell, the Style is null, so when you take out the Style, you should first determine whether its value is null. If the value is empty, you need to create a new Style first, and then assign the value to the CellElement. Finally, according to the methods in Style and FRFont, further set various attributes of the cell.
2.1 Create Cell
Create a new cell, the position is (1,1), the column direction occupies 2 cells, the row direction occupies 2 cells, the text value is "FineReport". The initial value of the position is (0,0)
TemplateCellElement cellElement = new DefaultTemplateCellElement(1, 1, 2, 2, "FineReport");
2.2 Set the Cell Row Height and Column Width
Set the width of the second column to 300px, set the height of the second row to 30px, and the row and column numbers start from 0
worksheet.setColumnWidth(1, new OLDPIX(300));
worksheet.setRowHeight(1, new OLDPIX(30));
2.3 Get Cell Style
Get the style of CellElement, if there is no new default style
Style style = cellElement.getStyle();
if (style == null) {
style = Style.getInstance();
}
2.4 Set Cell Style
cellElement.setStyle(style);
2.5 Set Detailed Style
Set font, font size, color, background and layout
FRFont frFont = FRFont.getInstance("Dialog", Font.BOLD, 16);
frFont = frFont.applyForeground(new Color(21, 76, 160));
style = style.deriveFRFont(frFont);
ColorBackground background = ColorBackground.getInstance(new Color(255, 255, 177));
style = style.deriveBackground(background);
style = style.deriveHorizontalAlignment(Constants.CENTER);
2.6 Set Cell Border
Set the border style and border color
style = style.deriveBorder(Constants.LINE_DASH, Color.red, Constants.LINE_DOT, Color.gray, Constants.LINE_DASH_DOT, Color.BLUE, Constants.LINE_DOUBLE, Color.CYAN);
3. Preview
For code details of the above example, please see:
Compile the code and place SetCellElementStyle.class under %FR_HOME%\webapps\webroot\WEB-INF\classes\com\fr\demo. Start up the designer and visit the follwoing address in the browser: http://localhost:8075/webroot/decision/view/report?viewlet=com.fr.demo.SetCellElementStyle to see the defined web report. As it shown below: