好吧,经过思考,我发现这个问题可以用其他方法解决。
我们将使用列、组等属性
setPrintWhenExpression(DRIExpression expression)
1.
创建类,该类将处理、打印或不打印行。Dynamic具有用于执行此操作的抽象类:
public class ShowExpressionDynamicReports extends AbstractSimpleExpression<Boolean> {
private String fieldName;
public ShowExpressionDynamicReports(String fieldName) {
this.fieldName = fieldName;
}
@Override
public Boolean evaluate(net.sf.dynamicreports.report.definition.ReportParameters reportParameters) {
return reportParameters.getValue(fieldName) != null;
}
}
您应该扩展AbstractSimpleExpression,以便将其作为参数传递给下面列出的方法。
因此,如果
evaluate(ReportParameters rp)
返回true
.
我还添加了字段
fieldName
这允许我打印(或不打印)列,因为
其他的
列状态。
2.
将属性添加到您的
列:
组:
.setPrintSubtotalsWhenExpression(DRIExpression expression)
或
setFooterPrintWhenExpression(DRIExpression expression)
或
setHeaderPrintWhenExpression(DRIExpression expression)
取决于你想隐藏什么。
例子:
我们在报告中有两列:Product和ProductCount列。如果ProductCount为空(我们没有此产品的信息),我想隐藏Product列。
为此,我将添加属性
PrintWhenExpression
到“产品”列
TextColumnBuilder<String> productColumn = col.column("Product", "Product", type.stringType())
.setPrintWhenExpression(new ShowExpressionDynamicReports("ProductCount"));