润乾集算报表通过API修改单元格属性

有时需要在程序中动态修改已做好报表的单元格属性,包括边框、字号、颜色、对齐方式等。润乾集算报表提供了丰富的API,开发人员可以通过提供的接口快速修改报表单元格属性。

  修改单元格属性主要修改报表定义ReportDefine,比如下面已经做好的订单信息表如下:

  

  预览效果:

  

  我们通过代码修改该报表单元格属性:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
//设定边框
        for  (int i = 2; i <=3; i++) {
            for  (int j = 1; j <=6; j++) {
               rd.setBBColor(i,(short)j, -6710887);  //设定下边框线色
               rd.setBBStyle(i,(short)j, INormalCell.LINE_SOLID);  //设定下边框类型
               rd.setBBWidth(i,(short)j, (float)0.75);  //设定下边框线粗
               //左边框
               rd.setLBColor(i,(short)j, -6710887);
               rd.setLBStyle(i,(short)j, INormalCell.LINE_SOLID);
               rd.setLBWidth(i,(short)j, (float)0.75);
               //右边框
               rd.setRBColor(i,(short)j, -6710887);
               rd.setRBStyle(i,(short)j, INormalCell.LINE_SOLID);
               rd.setRBWidth(i,(short)j, (float)0.75);
               //上边框
               rd.setTBColor(i,(short)j, -6710887);
               rd.setTBStyle(i,(short)j, INormalCell.LINE_SOLID);
               rd.setTBWidth(i,(short)j, (float)0.75);
            }
        }
  
        //设置单元格值、字体、字号、颜色、对齐等
        INormalCell inc = rd.getCell(1, (short) 1);
        inc.setValue( "订单信息表" );  //设置单元格值
        inc.setFontName( "宋体" );  //设置字体
        inc.setFontSize((short) 20);  //设置字号
        inc.setForeColor(-16777216); //设置前景色
        inc.setHAlign(INormalCell.VALIGN_MIDDLE); //设置横向对齐方式
        inc.setHAlign(INormalCell.HALIGN_CENTER); //设置纵向对齐方式

 

   报表定义修改后,使用defineBean方式发布报表:

     request.setAttribute("reportDefine",rd);

 

   修改后的报表发布后效果如下:

   

 

可以看到,增加了报表标题(内容、字体、颜色、对齐方式等),增加了单元格边框,更多修改单元格属性的方法可以参考《润乾集算报表应用开发手册》。

 

 

【附】changeCellProperty.jsp完整代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<%@page import= "com.raqsoft.report.usermodel.INormalCell" %>
<%@ page contentType= "text/html;charset=GBK" %>
<%@ taglib uri= "/WEB-INF/raqsoftReport.tld" prefix= "report" %>
<%@ page import= "java.io.*" %>
<%@ page import= "java.util.*" %>
<%@ page import= "com.raqsoft.report.usermodel.Context" %>
<%@ page import= "com.raqsoft.report.model.ReportDefine" %>
<%@ page import= "com.raqsoft.report.util.ReportUtils" %>
<%@page import= "com.raqsoft.report.usermodel.INormalCell" %>
  
  
<html>
<link type= "text/css" href= "css/style.css"  rel= "stylesheet"  />
<body topmargin=0 leftmargin=0 rightmargin=0 bottomMargin=0>
     <%
        request.setCharacterEncoding( "GBK" );
        String reportPath = request.getRealPath( "/WEB-INF/reportFiles/ccp.rpx" );
        ReportDefine rd = (ReportDefine) ReportUtils.read(reportPath);
        //设定边框
        for  (int i = 2; i <=3; i++) {
            for  (int j = 1; j <=6; j++) {
               rd.setBBColor(i,(short)j, -6710887);  //设定下边框线色
               rd.setBBStyle(i,(short)j, INormalCell.LINE_SOLID);  //设定下边框类型
               rd.setBBWidth(i,(short)j, (float)0.75);  //设定下边框线粗
               //左边框
               rd.setLBColor(i,(short)j, -6710887);
               rd.setLBStyle(i,(short)j, INormalCell.LINE_SOLID);
               rd.setLBWidth(i,(short)j, (float)0.75);
               //右边框
               rd.setRBColor(i,(short)j, -6710887);
               rd.setRBStyle(i,(short)j, INormalCell.LINE_SOLID);
               rd.setRBWidth(i,(short)j, (float)0.75);
               //上边框
               rd.setTBColor(i,(short)j, -6710887);
               rd.setTBStyle(i,(short)j, INormalCell.LINE_SOLID);
               rd.setTBWidth(i,(short)j, (float)0.75);
            }
        }
  
        //设置单元格值、字体、字号、颜色、对齐等
        INormalCell inc = rd.getCell(1, (short) 1);
        inc.setValue( "订单信息表" );  //设置单元格值
        inc.setFontName( "宋体" );  //设置字体
        inc.setFontSize((short) 20);  //设置字号
        inc.setForeColor(-16777216); //设置前景色
        inc.setHAlign(INormalCell.VALIGN_MIDDLE); //设置横向对齐方式
        inc.setHAlign(INormalCell.HALIGN_CENTER); //设置纵向对齐方式
        
       String rptName = "RPT_"+Double.toString(Math.random());            request.setAttribute(rptName,rd);
        
     %>
     <jsp:include page= "toolbar.jsp"  flush= "false"  />
     <table id= "rpt"  align= "center" width=100% height=100%>
        <tr>
            <td align=center valign=top height=100%>
            <report:html name= "report1"
               funcBarLocation= "" 
               srcType= "defineBean" 
             beanName="<%=rptName%>"
               exceptionPage= "/reportJsp/jsp/myError.jsp"  /></td>
        </tr>
     </table>
  
</body>
</html>
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值