多语言展示
当前在线:826今日阅读:60今日分享:41

erp报表二次开发单元格格式设置

erp报表二次开发单元格格式设置
工具/原料

erp报表二次开发:finereport

方法/步骤
1

1. 实现原理1.1 新建单元格新建一个单元格,位置为(1,1),列向占2个单元格,行向占2个单元格,文本值为 'FineReport',位置从(0,0)开始TemplateCellElement cellElement = new DefaultTemplateCellElement(1, 1, 2, 2, 'FineReport');         if (style == null) {                style = Style.getInstance();            }  1.设置单元格样式/设置单元格单元格的样式cellElement.setStyle(style);

2

1.2 设置单元格行高、列宽设置第1列宽为300px,设置第1行高为30px,行列编号都是从0开始worksheet.setColumnWidth(1, new OLDPIX(300));            worksheet.setRowHeight(1, new OLDPIX(30));  1.3 获取单元格样式得到CellElement的样式,如果没有新建默认样式Style style = cellElement.getStyle();

3

1.5 设置字体、字号等// 设置字体和前景的颜色     FRFont frFont = FRFont.getInstance('Dialog', Font.BOLD, 16);     frFont = frFont.applyForeground(new Color(21, 76, 160));     style = style.deriveFRFont(frFont);

4

// 设置背景     ColorBackground background = ColorBackground.getInstance(new Color(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);

5

2. 实现步骤改变单元格的格式,应先取出该单元格(CellElement)的格式(Style)。若您是新建一个单元格,则Style是null,故当取出Style后应先判断其值是否为null,如果这个值为空,则需先新建一个Style,然后再将该值赋给CellElement。最后根据Style和FRFont中的方法进一步地设置该单元格的各种属性。可执行代码如下://单元格格式设置  package com.fr.demo;        import java.awt.Color;    import java.awt.Font;  import java.util.Map;

6

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;  import com.fr.main.TemplateWorkBook;    import com.fr.main.impl.WorkBook;          public class SetCellElementStyle extends Reportlet {        public TemplateWorkBook createReport(ReportletRequest arg0) {

7

// 新建报表            WorkBook workbook = new WorkBook();            WorkSheet worksheet = new WorkSheet();            // 新建一个单元格,位置为(1,1),列占2单元格,行占2单元格,文本值为 'FineReport'            TemplateCellElement cellElement = new DefaultTemplateCellElement(1, 1,                    2, 2, 'FineReport');            // 设置列宽为300px,设置行高为30px            worksheet.setColumnWidth(1, new OLDPIX(300));            worksheet.setRowHeight(1, new OLDPIX(30));            // 得到CellElement的样式,如果没有新建默认样式            Style style = cellElement.getStyle();            if (style == null) {                style = Style.getInstance();            }

8

// 设置字体和前景的颜色            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);            // 设置边框            style = style.deriveBorder(Constants.LINE_DASH, Color.red,                    Constants.LINE_DOT, Color.gray, Constants.LINE_DASH_DOT,                    Color.BLUE, Constants.LINE_DOUBLE, Color.CYAN);

9

// 改变单元格的样式            cellElement.setStyle(style);            // 将单元格添加到报表中            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                }    }

10

2.1 发布并预览将编译后的SetCellElementStyle.class类放置在应用WEB-INF\classes\com\fr\demo下,启动服务器,在浏览器中访问该程序网络报表,地址如下:http://localhost:8075/WebReport/ReportServer?reportlet=com.fr.demo.SetCellElementStyle便可以看到我们定义的网络报表了。END

推荐信息