forked from demo/example
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
70 lines
2.5 KiB
70 lines
2.5 KiB
6 years ago
|
//单元格格式设置
|
||
|
package com.fr.demo;
|
||
|
|
||
6 years ago
|
import java.awt.Color;
|
||
|
import java.awt.Font;
|
||
|
import java.util.Map;
|
||
6 years ago
|
import com.fr.base.Style;
|
||
|
import com.fr.base.background.ColorBackground;
|
||
|
import com.fr.general.FRFont;
|
||
|
import com.fr.report.cell.DefaultTemplateCellElement;
|
||
|
import com.fr.report.cell.TemplateCellElement;
|
||
|
import com.fr.report.worksheet.WorkSheet;
|
||
|
import com.fr.stable.Constants;
|
||
|
import com.fr.stable.unit.OLDPIX;
|
||
|
import com.fr.web.core.Reportlet;
|
||
|
import com.fr.web.request.ReportletRequest;
|
||
6 years ago
|
import com.fr.main.TemplateWorkBook;
|
||
|
import com.fr.main.impl.WorkBook;
|
||
6 years ago
|
|
||
|
|
||
|
public class SetCellElementStyle extends Reportlet {
|
||
|
public TemplateWorkBook createReport(ReportletRequest arg0) {
|
||
6 years ago
|
// 新建报表
|
||
6 years ago
|
WorkBook workbook = new WorkBook();
|
||
|
WorkSheet worksheet = new WorkSheet();
|
||
6 years ago
|
// 新建一个单元格,位置为(1,1),列占2单元格,行占2单元格,文本值为 "FineReport"
|
||
6 years ago
|
TemplateCellElement cellElement = new DefaultTemplateCellElement(1, 1,
|
||
|
2, 2, "FineReport");
|
||
6 years ago
|
// 设置列宽为300px,设置行高为30px
|
||
6 years ago
|
worksheet.setColumnWidth(1, new OLDPIX(300));
|
||
|
worksheet.setRowHeight(1, new OLDPIX(30));
|
||
6 years ago
|
// 得到CellElement的样式,如果没有新建默认样式
|
||
6 years ago
|
Style style = cellElement.getStyle();
|
||
|
if (style == null) {
|
||
|
style = Style.getInstance();
|
||
|
}
|
||
6 years ago
|
// 设置字体和前景的颜色
|
||
6 years ago
|
FRFont frFont = FRFont.getInstance("Dialog", Font.BOLD, 16);
|
||
|
frFont = frFont.applyForeground(new Color(21, 76, 160));
|
||
|
style = style.deriveFRFont(frFont);
|
||
6 years ago
|
// 设置背景
|
||
6 years ago
|
ColorBackground background = ColorBackground.getInstance(new Color(255,
|
||
|
255, 177));
|
||
|
style = style.deriveBackground(background);
|
||
6 years ago
|
// 设置水平居中
|
||
6 years ago
|
style = style.deriveHorizontalAlignment(Constants.CENTER);
|
||
6 years ago
|
// 设置边框
|
||
6 years ago
|
style = style.deriveBorder(Constants.LINE_DASH, Color.red,
|
||
|
Constants.LINE_DOT, Color.gray, Constants.LINE_DASH_DOT,
|
||
|
Color.BLUE, Constants.LINE_DOUBLE, Color.CYAN);
|
||
6 years ago
|
// 改变单元格的样式
|
||
6 years ago
|
cellElement.setStyle(style);
|
||
6 years ago
|
// 将单元格添加到报表中
|
||
6 years ago
|
worksheet.addCellElement(cellElement);
|
||
|
workbook.addReport(worksheet);
|
||
|
return workbook;
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public void setParameterMap(Map arg0) {
|
||
|
// TODO Auto-generated method stub
|
||
|
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public void setTplPath(String arg0) {
|
||
|
// TODO Auto-generated method stub
|
||
|
|
||
|
}
|
||
|
}
|