colour报表开发单元格格式设置
1、实现原理1.1新建单元格新建一个单元格,位置为(1,1),列向占2个单元格,行向占2个单元格,文本值设置第1列宽为300px,设置第1行高为30px,行列编号都是从0开始worksheet.setColumnWidth(1,newOLDPIX(300));worksheet.setRowHeight(1,newOLDPIX(30));
2、3获取单元格样式得到CellElement的样式,如果没有新建默认样式Stylestyle=cellElement.getStyle();if(style==null){style=Style.getInstance();}1.4设置单元格样式/设置单元格单元格的样式cellElement.setStyle(style);
3、猱蝰逾鸾5设置字体、字号等//设置字体和前景的颜色FRFontfrFont=FRFont.getInstance烫喇霰嘴("Dialog",Font.BOLD,16);frFont=frFont.applyForeground(newColor(21,76,160));style=style.deriveFRFont(frFont);//设置背景ColorBackgroundbackground=ColorBackground.getInstance(newColor(255,255,177));style=style.deriveBackground(background);//设置水平居中style=style.deriveHorizontalAlignment(Constants.CENTER);1.6设置单元格边框设置边框样式和边框颜色style=style.deriveBorder(Constants.LINE_DASH,Color.red,Constants.LINE_DOT,Color.gray,Constants.LINE_DASH_DOT,Color.BLUE,Constants.LINE_DOUBLE,Color.CYAN);
4、实现步骤改变单元格的格式,应先取出该单元格(CellElement)的格式(Style)。若您是新建一个单元格,则Style是null,故当取出Style后应先判断其值是否为null,如果这个值为空,则需先新建一个Style,然后再将该值赋给CellElement。最后根据Style和FRFont中的方法进一步地设置该单元格的各种属性。可执行代码如下://单元格格式设置packagecom.fr.demo;importjava.awt.Color;importjava.awt.Font;importjava.util.Map;importcom.fr.base.Style;importcom.fr.base.background.ColorBackground;importcom.fr.general.FRFont;importcom.fr.report.cell.DefaultTemplateCellElement;importcom.fr.report.cell.TemplateCellElement;importcom.fr.report.worksheet.WorkSheet;importcoquest; importcom.fr.main.TemplateWorkBook;importcom.fr.main.impl.WorkBook;
5、publicclassSetCellElementStyleextendsReportlet{publicTemplateWorkBookcreateReport(ReportletRequestarg0){//新建报表WorkBookworkbook=newWorkBook();WorkSheetworksheet=newWorkSheet();//新建一个单元格,位置为(1,1),列占2单元格,行占2单元格,文本值为"FineReport"TemplateCellElementcellElement=newDefaultTemplateCellElement(1,1,2,2,"FineReport");//设置列宽为300px,设置行高为30pxworksheet.setColu1,newOLDPIX(30)); //得到CellElement的样式,如果没有新建默认样式Stylestyle=cellElement.getStyle();if(style==null){style=Style.getInstance();}
6、 //设置字体和前景的颜色FRFontfrFont=FRFont.getInstance("Dialog",Font.BOLD,16);frFont=frFont.applyForeground(newColor(21,76,160));style=style.deriveFRFont(frFont);//设置背景ColorBackgroundbackgroound); //设置水平居中style=style.deriveHorizontalAlignment(Constants.CENTER);//设置边框style=style.deriveBorder(Constants.LINE_DASH,Color.red,Constants.LINE_DOT,Color.gray,Constants.LINE_DASH_DOT,Color.BLUE,Constants.LINE_DOUBLE,Color.CYAN);
7、服务器配置要求最低配置CPU类型:需要PentiumIII兼容或更高速度的处理器CPU速度:2.1GHz或更高内存:2G硬盘空间:250G推荐配置CPU类型:需要 Pentium III 兼容或更高速度的处理器CPU速度:3.8GHz或更高内存:8G硬盘空间:1TG
8、 //改变单元格的样式cellElement.setStyle(style);//将单元格添加到报表中worksheet.addCellElement(cellElement);workbook.addReport(worksheet);returnworkbook;}@OverridepublicvoidsetParameterMap(Maparg0){//TODOAuto-generatedmethodstub}@OverridepublicvoidsetTplPath(Stringarg0){//TODOAuto-generatedmethodstub}}
9、1发布并预览将编译后的SetCellElementStyle.class类放置在应用WEB-INF\classes\com\fr\demo下,启动服务器,在浏览器中访问该程序网络报表,地址如下:http://localhost:8075/WebReport/ReportServer?reportlet=com.fr.demo.SetCellElementStyle便可以看到我们定义的网络报表了。