API 创建 rpx 文件

背景说明

有些业务,不方便在报表设计工具—设计器中设计好报表文件,而是在代码中,临时创建报表文件,这时,润乾报表用代码怎么创建报表文件呢,我们来看一个简单例子。

应用举例

<%@ page contentType=“text/html;charset=gb2312” %>

<%@ page import=“com.raqsoft.report.usermodel.*”%>

<%@ page import=“com.raqsoft.report.model.*”%>

<%@ page import=“com.raqsoft.report.model.ReportDefine”%>

<%@ page import=“com.raqsoft.report.util.ReportUtils” %>

<%@ page import=“com.raqsoft.report.view.html.*” %>

<%

        // 新建一个空白报表

        String reportFileHome=Context.getInitCtx().getMainDir();

        ReportDefine rd=new ReportDefine2(3,3);

        // 设置报表的常规属性

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

                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.rpx”,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());

%>

润乾报表 5 示例