API动态隐藏报表的行和列

需求背景:

我们实现报表的行列隐藏,通常在报表设计的时候,可分别通过属性窗口中的隐藏行、隐藏类通过勾选或设定条件判断表达式实现,我们如何在发布报表时通过参数动态的去设定报表数据列数据行的隐藏呢?

实现思路:

读取报表,生成一个ReportDefine报表定义对象,通过getRowCell方法获得指定行的行首格,然后对该行首格设定显示隐藏,将修改了单元格属性的单元格对象,使用setRowCell方法设置为相应数据行的首行格,通过defineBean方式发布报表。

具体代码:

import com.geezn.report4.model.ReportDefine;

import com.geezn.report4.model.engine.ExtCellSet;

import com.geezn.report4.usermodel.Context;

import com.geezn.report4.usermodel.Engine;

import com.geezn.report4.usermodel.IReport;

import com.geezn.report4.usermodel.IRowCell;

import com.geezn.report4.util.ReportUtils;

import com.geezn.report4.view.word.WordReport;

import com.geezn.report4.view.xml.XMLReport;

public class TestRowVisible {

public static void main(String[] args) throws Throwable {

Context cxt = new Context(); //构建报表引擎计算环境

String reportFile = “D:/neijian_ myd.raq”; //该文件名可以为绝对路径,也可以相对当前程序启动路径

ExtCellSet.setLicenseFileName(“D:\\Server2011-06-30V4.0Windows.lic”); //设置授权文件

ReportDefine rd = (ReportDefine)ReportUtils.read( reportFile );

IRowCell rowcell=rd.getRowCell(1);

rowcell.setRowVisible(false);

rd.setRowCell(1, rowcell);

Engine engine = new Engine(rd, cxt); //构造报表引擎

IReport iReport = engine.calc(); //运算报表

ReportUtils.exportToHTML(“D:/test1.html”, iReport);

}

}

该小例是设置了报表的第一行进行隐藏,然后将修改后的报表定义对象计算为iReport输出为html文件。