润乾报表api创建raq文件
◆ 背景说明
有些业务,不方便在报表设计工具—设计器中设计好报表文件,而是在代码中,临时创建报表文件,这时,快逸报表用代码怎么创建报表文件呢,我们来看一个简单例子。
◆ 应用举例
新建一个jsp页面,在jsp页面中写如下代码:
<%@ page contentType=”text/html;charset=gb2312″ %>
<%@ page import=”java.io.*”%>
<%@ page import=”com.runqian.report4.usermodel.*”%>
<%@ page import=”com.runqian.report4.model.NormalCell”%>
<%@ page import=”com.runqian.report4.model.ReportDefine”%>
<%@ page import=”com.runqian.report4.model.ReportDefine2″%>
<%@ page import=”com.runqian.report4.view.html.*”%>
<%@ page import=”com.runqian.report4.util.*”%>
<%@ page import=”com.runqian.report4.view.excel.*”%>
<%@ page import=”com.runqian.report4.view.excel.ExcelReport”%>
<%
//第一步,创建空报表模板
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());
%>