如何汇总Jaspersoft iReport Designer中列中的所有值? [英] How to sum all values in a column in Jaspersoft iReport Designer?

查看:125
本文介绍了如何汇总Jaspersoft iReport Designer中列中的所有值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Jaspersoft iReport Designer中有类似的报告,但是无法弄清楚如何将垂直列医生付款中的所有值加起来得到1601?这列的长度是可变的(即行数根据数据库的大小及其更新频率而变化)。

I have below similar report in Jaspersoft iReport Designer, but not able to figure out how to sum all values present in vertical column "Doctor Payment" to get a total of "1601"? Length of this columns is variable (i.e. no of rows vary according to size of database & its update frequency ).

是否有像这样的变量$ V {COLUMN_COUNT} (实际上没有行,这里是5),
给出了列中所有值的总和?如果不是,怎么做总和

Is there any variable like $V{COLUMN_COUNT} (actually gives no of rows, here 5), which gives sum of all values in a column? If no, how to do sum?

Doctor ID   Doctor Payment
 A1             123
 B1             223
 C2             234
 D3             678
 D1             343
Total          1601


推荐答案

解决您的任务非常容易。您应该创建并使用新变量来汇总医生付款列的值。

It is quite easy to solve your task. You should create and use a new variable for summing values of the "Doctor Payment" column.

在你的情况下,变量可以这样声明:

In your case the variable can be declared like this:

<variable name="total" class="java.lang.Integer" calculation="Sum">
    <variableExpression><![CDATA[$F{payment}]]></variableExpression>
</variable>




  • 计算类型总和;

  • 重置类型报告;

  • 变量表达式 $ F {payment} ,其中 $ F {payment} 是包含总和的字段名称( Doctor Payment )。

    • the Calculation type is Sum;
    • the Reset type is Report;
    • the Variable expression is $F{payment}, where $F{payment} is the name of a field contains sum (Doctor Payment).
    • 工作示例。

      CSV数据源:

      
      doctor_id,payment
      A1,123
      B1,223
      C2,234
      D3,678
      D1,343
      

      模板:

      <?xml version="1.0" encoding="UTF-8"?>
      <jasperReport ...>
          <queryString>
              <![CDATA[]]>
          </queryString>
          <field name="doctor_id" class="java.lang.String"/>
          <field name="payment" class="java.lang.Integer"/>
          <variable name="total" class="java.lang.Integer" calculation="Sum">
              <variableExpression><![CDATA[$F{payment}]]></variableExpression>
          </variable>
          <columnHeader>
              <band height="20" splitType="Stretch">
                  <staticText>
                      <reportElement x="0" y="0" width="100" height="20"/>
                      <box leftPadding="10"/>
                      <textElement textAlignment="Center" verticalAlignment="Middle">
                          <font size="10" isBold="true" isItalic="true"/>
                      </textElement>
                      <text><![CDATA[Doctor ID]]></text>
                  </staticText>
                  <staticText>
                      <reportElement x="100" y="0" width="100" height="20"/>
                      <box leftPadding="10"/>
                      <textElement textAlignment="Center" verticalAlignment="Middle">
                          <font size="10" isBold="true" isItalic="true"/>
                      </textElement>
                      <text><![CDATA[Doctor Payment]]></text>
                  </staticText>
              </band>
          </columnHeader>
          <detail>
              <band height="20" splitType="Stretch">
                  <textField>
                      <reportElement x="0" y="0" width="100" height="20"/>
                      <box leftPadding="10"/>
                      <textElement/>
                      <textFieldExpression><![CDATA[$F{doctor_id}]]></textFieldExpression>
                  </textField>
                  <textField>
                      <reportElement x="100" y="0" width="100" height="20"/>
                      <box leftPadding="10"/>
                      <textElement/>
                      <textFieldExpression><![CDATA[$F{payment}]]></textFieldExpression>
                  </textField>
              </band>
          </detail>
          <summary>
              <band height="20">
                  <staticText>
                      <reportElement x="0" y="0" width="100" height="20"/>
                      <box leftPadding="10"/>
                      <textElement>
                          <font isBold="true"/>
                      </textElement>
                      <text><![CDATA[Total]]></text>
                  </staticText>
                  <textField>
                      <reportElement x="100" y="0" width="100" height="20"/>
                      <box leftPadding="10"/>
                      <textElement>
                          <font isBold="true" isItalic="true"/>
                      </textElement>
                      <textFieldExpression><![CDATA[$V{total}]]></textFieldExpression>
                  </textField>
              </band>
          </summary>
      </jasperReport>
      

      结果将是:

      你可以在 JasperReports终极指南

      这篇关于如何汇总Jaspersoft iReport Designer中列中的所有值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆