知识库

推荐内容

快逸做的更好

产品优势

您的位置: 首页 > 知识库 > 设计基础 > api创建raq文件

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());
%>

本文标签:
发布日期:2011/04/18
本文分类: 设计基础