您的位置:首页 > 其它

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

2015-04-15 11:04 183 查看
有时需要在程序中动态修改已做好报表的单元格属性,包括边框、字号、颜色、对齐方式等。润乾集算报表提供了丰富的API,开发人员可以通过提供的接口快速修改报表单元格属性。
修改单元格属性主要修改报表定义ReportDefine,比如下面已经做好的订单信息表如下:



预览效果:


我们通过代码修改该报表单元格属性:
//设定边框
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);
}
}

//设置单元格值、字体、字号、颜色、对齐等
INormalCellinc = 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完整代码:
<%@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");
StringreportPath = request.getRealPath("/reportFiles/ccp.rpx");
ReportDefinerd = (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); } } //设置单元格值、字体、字号、颜色、对齐等 INormalCellinc = 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);//设置纵向对齐方式

request.setAttribute("reportDefine",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="reportDefine"
exceptionPage="/reportJsp/jsp/myError.jsp" /></td>
</tr>
</table>

</body>
</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐