bean发布的报表添加随机名称
来源:互联网 发布:手机淘宝店如何装修 编辑:程序博客网 时间:2024/06/06 02:13
润乾报表除了正常的读取raq发布报表外,为了满足不同层次的需要,润乾tag还支持definebean的方式发布报表、支持传递context对象,便于用户自定义数据源、自定义参数和宏等。使用bean的形式发布报表需要生存definebean或者ireport对象,如果要动态的生成报表,必须随机生存报表对象才能发布。
步骤一,利用api创建报表
<%@ page contentType=”text/html;charset=GBK” %>
<%@ taglib uri=”/WEB-INF/runqianReport4.tld” prefix=”report” %>
<%@ page import=”java.io.*”%>
<%@ page import=”com.runqian.report4.usermodel.*”%>
<%@ page import=”com.runqian.report4.model.*”%>
<%@ page import=”com.runqian.report4.util.*”%>
<%
// 新建一个默认的空报表
ReportDefine rd = new ReportDefine2(2, 3);
// 设置数据集
SQLDataSetConfig dsc = new SQLDataSetConfig();
dsc.setName(“ds1″);
dsc.setSQL(“SELECT * FROM customer”);
DataSetMetaData dsmt = new DataSetMetaData();
dsmt.addDataSetConfig(dsc);
rd.setDataSetMetaData(dsmt);
// 设置单元格值
INormalCell icell_11 = rd.getCell(1, (short) 1);
INormalCell icell_12 = rd.getCell(1, (short) 2);
INormalCell icell_13 = rd.getCell(1, (short) 3);
icell_11.setValue(“客户类型“);
icell_12.setValue(“客户名“);
icell_13.setValue(“电话“);
// 设置单元格表达式
INormalCell icell_21 = rd.getCell(2, (short) 1);
ByteMap exp = new ByteMap();
exp.put(INormalCell.VALUE, “ds1.Group(customertype)”);
//exp.put(INormalCell.DISPVALUE, “ds2.select1(typename,typeid==value())”);//设置显示格式
icell_21.setExpMap(exp);
INormalCell icell_22 = rd.getCell(2, (short) 2);
ByteMap exp2 = new ByteMap();
exp2.put(INormalCell.VALUE, “ds1.select(customer_name)”);
icell_22.setExpMap(exp2);
INormalCell icell_23 = rd.getCell(2, (short) 3);
ByteMap exp3 = new ByteMap();
exp3.put(INormalCell.VALUE, “ds1.tel”);
icell_23.setExpMap(exp3);
// 设置边框样式
for (int i = 1; i <= rd.getRowCount(); i++) {
for (short j = 1; j <= rd.getColCount(); j++) {
rd.setBBColor(i, j, -16777216);//
rd.setBBStyle(i, j, INormalCell.LINE_SOLID);
rd.setBBWidth(i, j, (float) 0.75);
rd.setLBColor(i, j, -16777216);
rd.setLBStyle(i, j, INormalCell.LINE_SOLID);
rd.setLBWidth(i, j, (float) 0.75);
rd.setRBColor(i, j, -16777216);
rd.setRBStyle(i, j, INormalCell.LINE_SOLID);
rd.setRBWidth(i, j, (float) 0.75);
rd.setTBColor(i, j, -16777216);
rd.setTBStyle(i, j, INormalCell.LINE_SOLID);
rd.setTBWidth(i, j, (float) 0.75);
}
}
//输出到本地
OutputStream out1 = new FileOutputStream( “D:\\test.raq” );
ReportUtils.write(out1,rd);
out1.close();
步骤二,使用随机数为生成的报表命名
//设置request中报表定义对象
String rptName = “RPT_”+Double.toString(Math.random());
request.setAttribute(rptName,rd);
直接调用Math.random()是产生一个[0,1)之间的随机数,
如果用
java.util.Random random=new Random();random.nextInt()这样产生一个长整型的随机数并且与上一次是一样的,如果过一会再产生就不会一样了,例如:
for (int i = 0; i < 10; i++) {
Random random=new Random();
Thread.sleep(100);
System.out.print((int)random.nextInt(100)+” “);
}
就是产生不同的随机Long数了
如果想用java.util.Random()产生指定范围的随机数就需要进行求模运算,进行一些处理
步骤三,html内beanname发布报表
<report:html name=”report1″
srcType=”defineBean”
beanName=”<%=rptName%>”
/>
- bean发布的报表添加随机名称
- 语义报表的发布
- 报表的发布
- 修改项目的发布名称
- Spring 根据Bean注册的名称获取Bean对象
- Spring 根据Bean注册的名称获取Bean对象
- SSH 根据bean的名称获得bean实体工具类
- 水晶报表发布的资源
- 4.4、SSRS-报表的发布
- [水晶报表]如何更改水晶报表导出文件的名称
- 添加随机的游戏元素
- 添加随机的游戏元素
- 不使用项目名称的发布方式
- Eclipse 修改Web项目的发布名称
- 如何更改项目的发布名称
- TOMCAT发布后的名称修改
- 修改myeclipse发布的项目名称
- 报表删除时报错“请先删除发布的报表”
- request:fail 小程序要求的 TLS 版本必须大于等于 1.2
- 安卓源生实现计时器效果
- 移植QT4.8.7
- Android R.java resource's Ids Non-constant Fields in Case Labels
- sublime text 3 添加头文件代码段
- bean发布的报表添加随机名称
- ”_SecCertificateCopyData", referenced from:
- Java语言核心-使用try-catch捕获单个异常
- Python 日期和时间
- java基础学习
- 利用scikit-learn进行人脸表面关键点的定位
- 图片鉴黄的原理和应用
- Android之用sharedUserId来实现不同应用(APK)数据共享
- Xcode常见警告汇总(持续更新)