通过润乾的api创建报表文件

来源:互联网 发布:软件架构设计师挂靠 编辑:程序博客网 时间:2024/06/05 03:38

有的时候根不方便在报表设计工具设计器中设计好报表文件,而是在代码中,临时创建报表文件,这里简单做个介绍:

具体代码如下:

//第一步,创建空报表模板
String reportFileHome=Context.getInitCtx().getMainDir();
ReportDefine rd = new ReportDefine2(3,3);
//第二步,设置报表属性
rd.setInput(ReportDefine.INPUT_NONE);
rd.setReportType(ReportDefine.RPT_NORMAL);
//第三步,给报表单元格写表达式
int rowCount = rd.getRowCount();
int ColCount = rd.getColCount();
for (int i = 1; i <= rowCount; i++) {
for (int j = 1; j <= ColCount; j++) {
INormalCell NCell = rd.getCell(i, (short) j);
NCell.setValue(i+j);
NCell.setBackColor(-1);
NCell.setForeColor(-65536);
rd.setBBColor(i,(short)j, -16763905); //设定下边框线色
rd.setBBStyle(i,(short)j, INormalCell.LINE_SOLID); //设定下边框类型
rd.setBBWidth(i,(short)j, (float) 0.75); //设定下边框线粗
//左边框
rd.setLBColor(i,(short)j, -16763905);
rd.setLBStyle(i,(short)j, INormalCell.LINE_SOLID);
rd.setLBWidth(i,(short)j, (float) 0.75);
//右边框
rd.setRBColor(i,(short)j, -16763905);
rd.setRBStyle(i,(short)j, INormalCell.LINE_SOLID);
rd.setRBWidth(i,(short)j, (float) 0.75);
//上边框
rd.setTBColor(i,(short)j, -16763905);
rd.setTBStyle(i,(short)j, INormalCell.LINE_SOLID);
rd.setTBWidth(i,(short)j, (float) 0.75);
}
}
//将ReportDefine保存到文件
try { ReportUtils.write(application.getRealPath(reportFileHome)+"\\testApi.raq",rd);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//第四步,运算报表
Context context = new Context();
Engine enging = new Engine( rd, context);
IReport iReport = enging.calc();
//第五步,展现
HtmlReport hReport = new HtmlReport( iReport,"report1" );
out.print(hReport.generateHtml());

这样一个简单的raq文件就生成了。



原创粉丝点击