Jasper reports 如何在“中使用动态变量”;当表达式“0”时打印;?

Jasper reports 如何在“中使用动态变量”;当表达式“0”时打印;?,jasper-reports,ireport,Jasper Reports,Ireport,我正在使用iReport制作PDF报告。 我的目标是在我的3个对象元素中使用动态变量(变量名称为pgnum),并在“表达式打印”对象属性中使用pgnum。 我有三个objects元素,它们是文本字段、frame name的frameA和frame name的frameB 我想在打印时制作如下内容: 文本字段=当表达式:$V{pgnum}%6==1时打印 frameA=当表达式:$V{pgnum}%6==1时打印 frameB=表达式为%6时打印:$V{pgnum}=1 如果我的PDF中总共有

我正在使用iReport制作PDF报告。
我的目标是在我的3个对象元素中使用动态变量(变量名称为pgnum),并在“表达式打印”对象属性中使用pgnum
我有三个objects元素,它们是文本字段、frame name的frameA和frame name的frameB

我想在打印时制作如下内容:

  • 文本字段=当表达式:$V{pgnum}%6==1时打印
  • frameA=当表达式:$V{pgnum}%6==1时打印
  • frameB=表达式为%6时打印:$V{pgnum}=1
如果我的PDF中总共有14页,那么我想要的结果是:

  • 在打印第7页和第13页时,将打印文本字段和框架A
  • 而另一页(第7页和第13页除外)将只打印框架B
我一直在iReport中尝试,但是pgnum始终是静态结果,即使在文本字段中,评估时间属性也适用于每个页面。帧A永远不会被打印,因为我认为pgnum总是被设置为零(0)值,并且永远不会是递增的。 因此,结果是在所有页面中始终打印第B帧

你能帮我用iReport解决这个问题吗? 或者你能建议或者甚至帮助我使用其他jasper报告,比如动态报告或者动态jasper来解决这个问题吗

注意:

  • 动态变量的名称为pgnum
  • 我的pgnum具有初始值0(零)
  • 并且具有如下属性=>class=“java.lang.Integer”incrementType=“Page”calculation=“Sum”
谢谢你的阅读。 我很快就等你的答复

以下是我的jrxml文件:


谢谢Alex K的回复,但是你的回答仍然不能解决我的问题,我已经尝试并按照你的命令解决这个问题,但是我仍然得到静态值(不是增量)中的pgnum

您以前向我建议过数据源,现在我已经在测试包中包含了新jrxml和数据源示例文件的问题。但是我有一个新问题,我创建的结果(dummyData)总是在test.pdf中打印为“空”,您能再次帮助我吗,先生?你能不能先解决我的主要目标

多谢各位 我在等你的答复

以下是链接:
变量的表达式错误

如果要使用0值开始计算,并为每个新页面将pgnum值增加1,则使用正确的表达式:


它类似于此伪代码:

intpgnum=0;
//遍历记录
// ....
如果(isNewPageStart()){
pgnum=pgnum+1;
}
如果要为pgnum设置初始值(例如借助参数initialValue),并为每个新页面将pgnum值增加1,则表达式将为:


它类似于此伪代码:

int initialValue=5;
int pgnum=初始值;
//遍历记录
// ....
如果(isNewPageStart()){
pgnum=pgnum+1;
}
还可以使用以下表达式将每个新页面的pgnum值增加1:


variableExpression应包含任何非空值。我已经设置了100个值,但我可以设置例如5或9


关于变量的信息 引用-主题变量:

变量名 与参数和字段一样,èvariable›元素的name属性为 必需,并允许在报表表达式中按声明的名称引用变量。 复位类型 报表变量的值可以随每次迭代而改变,但也可以改变 返回其初始值表达式在执行过程中的指定时间返回的值 报告填写过程。此行为使用resetType属性进行控制, 它指示在报告填充过程中应何时重新初始化变量。 变量有五种重置类型: *无重置:变量将永远不会使用其初始值表达式进行初始化 并且只包含通过计算变量表达式(resetType=“None”)获得的值。 *报告级别重置:变量仅在报告开始时初始化一次 报表填充过程,使用变量的初始值表达式(resetType=“report”)返回的值。 *页面级别重置:在每个新页面的开头重新初始化变量(resetType=“Page”)。 *列级重置:在每个新列的开头重新初始化变量(resetType=“Column”)。 *组级别重置:每次指定组时,都会重新初始化变量 resetGroup属性中断(resetType=“Group”)。此属性的默认值为resetType=“Report”。 增加型 此属性允许您选择增加变量的确切时刻。默认情况下, 变量随数据源中的每条记录而递增,但在具有多个 数据分组的级别,一些变量可能会计算更高级别的总计,并且需要 只是偶尔增加,而不是使用 Variable Name Just as for parameters and fields, the name attribute of the ‹variable› element is mandatory and allows referencing the variable by its declared name in report expressions. Reset Type The value of a report variable can change with every iteration, but it can be brought back to the value returned by its initial value expression at specified times during the report-filling process. This behavior is controlled using the resetType attribute, which indicates when the variable should be reinitialized during the report-filling process. There are five reset types for a variable: * No reset: The variable will never be initialized using its initial value expression and will only contain values obtained by evaluating the variable’s expressio (resetType="None"). * Report-level reset: The variable is initialized only once, at the beginning of the report-filling process, with the value returned by the variable’s initial value expression (resetType="Report"). * Page-level reset: The variable is reinitialized at the beginning of each new page (resetType="Page"). * Column-level reset: The variable is reinitialized at the beginning of each new column (resetType="Column"). * Group-level reset: The variable is reinitialized every time the group specified by the resetGroup attributes breaks (resetType="Group"). The default value for this attribute is resetType="Report". Increment Type This property lets you choose the exact moment to increment the variable. By default, variables are incremented with each record in the data source, but in reports with multiple levels of data grouping, some variables might calculate higher-level totals and would need to be incremented only occasionally, not with every iteration through the data source. This attribute uses the same values as the resetType attribute, as follows: * Row-level increment: The variable is incremented with every record during the iteration through the data source (incrementType="None"). * Report-level increment: The variable never gets incremented during the report-filling process (incrementType="Report"). * Page-level increment: The variable is incremented with each new page (incrementType= "Page"). * Column-level increment: The variable is incremented with each new column (incrementType="Column"). * Group-level increment: The variable is incremented every time the group specified by the incrementGroup attributes breaks (incrementType="Group"). CALCULATIONS As mentioned, variables can perform built-in types of calculations on their corresponding expression values. The following subsections describe all the possible values for the calculation attribute of the element. Calculation Nothing This is the default calculation type that a variable performs. It means that the variable’s value is recalculated with every iteration in the data source and that the value returned is obtained by simply evaluating the variable’s expression. Calculation Count A count variable includes in the count the non-null values returned after evaluating the variable’s main expression, with every iteration in the data source. Count variables must always be of a numeric type. However, they can have non-numeric expressions as their main expression since the engine does not care about the expression type, but only counts for the non-null values returned, regardless of their type. Only the variable’s initial value expression should be numeric and compatible with the variable’s type, since this value will be directly assigned to the count variable when initialized. Calculation DistinctCount This type of calculation works just like the Count calculation, the only difference being that it ignores repeating values and counts only for distinct non-null values. Calculation Sum The reporting engine can sum up the values returned by the variable’s main expression if you choose this type of calculation; but make sure the variable has a numeric type. You cannot calculate the sum of a java.lang.String or java.util.Date type of report variable unless a customized variable incrementer is used, as explained in the “Incrementers” section later in this chapter. Calculation Average The reporting engine can also calculate the average for the series of values obtained by evaluating the variable’s expression for each record in the data source. This type of calculation can be performed only for numeric variables (see the following “Incrementers” section, later in this chapter for details). Calculation Lowest and Highest Choose this type of calculation when you want to obtain the lowest or highest value in the series of values obtained by evaluating the variable’s expression for each data source record. Calculation StandardDeviation and Variance In some special reports, you might want to perform more advanced types of calculations on numeric expressions. JasperReports has built-in algorithms to obtain the standard deviation and the variance for the series of values returned by evaluation of a report variable’s expression. Calculation System This type of calculation can be chosen only when you don’t want the engine to calculate any value for your variable. That means you are calculating the value for that variable yourself, almost certainly using the scriptlets functionality of JasperReports. For this type of calculation, the only thing the engine does is to conserve the value you have calculated yourself, from one iteration in the data source to the next. Calculation First When using the calculation type First, the variable will keep the value obtained after the first incrementation and will not change it until the reset event occurs. Here is a simple report variable declaration that calculates the sum for a numeric report field called Quantity: ‹variable name="QuantitySum" class="java.lang.Double" calculation="Sum"› ‹variableExpression>$F{Quantity}‹/variableExpression› ‹/variable› If you want the sum of this field for each page, here’s the complete variable declaration: ‹variable name="QuantitySum" class="java.lang.Double" resetType="Page" calculation="Sum"› ‹variableExpression›$F{Quantity}‹/variableExpression› ‹initialValueExpression>new Double(0)‹/initialValueExpression› ‹/variable› In this example, our page sum variable will be initialized with zero at the beginning of each new page.