2014-09-23 64 views
0

这是我的Grandtotal代码,但它不会有grandtotal?Grand Total in report

<?xml version="1.0" encoding="UTF-8"?> 
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="Warehouse" language="groovy" pageWidth="612" pageHeight="792" columnWidth="572" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20"> 
    <queryString language="SQL"> 
     <![CDATA[select * from warehouse]]> 
    </queryString> 
    <field name="PlantUnit" class="java.lang.String"/> 
    <field name="Description" class="java.lang.String"/> 
    <field name="Size" class="java.lang.String"/> 
    <field name="Qty" class="java.lang.String"/> 
    <field name="Unit" class="java.lang.String"/> 
    <field name="Unit Price" class="java.lang.String"/> 
    <field name="Amount" class="java.lang.String"/> 
    <variable name="TotalAmount" class="java.lang.String" calculation="Sum"> 
     <variableExpression><![CDATA[$F{Amount}]]></variableExpression> 
    </variable> 
    <background> 
     <band splitType="Stretch"/> 
    </background> 
    <title> 
     <band height="40" splitType="Stretch"> 
      <staticText> 
       <reportElement x="100" y="0" width="409" height="40"/> 
       <textElement textAlignment="Center"> 
        <font fontName="Times New Roman" size="34" isBold="true"/> 
       </textElement> 
       <text><![CDATA[WAREHOUSE]]></text> 
      </staticText> 
     </band> 
    </title> 
    <pageHeader> 
     <band height="15" splitType="Stretch"> 
      <textField pattern="MMMMM dd, yyyy"> 
       <reportElement x="457" y="0" width="116" height="15"/> 
       <textElement textAlignment="Right"> 
        <font fontName="Times New Roman" size="12"/> 
       </textElement> 
       <textFieldExpression><![CDATA[new SimpleDateFormat("MMMM dd, yyyy").format(new java.util.Date())]]></textFieldExpression> 
      </textField> 
     </band> 
    </pageHeader> 
    <columnHeader> 
     <band height="12" splitType="Stretch"> 
      <staticText> 
       <reportElement x="0" y="0" width="50" height="12"/> 
       <textElement textAlignment="Center"> 
        <font fontName="Times New Roman" size="10" isBold="true"/> 
       </textElement> 
       <text><![CDATA[PU]]></text> 
      </staticText> 
      <staticText> 
       <reportElement x="50" y="0" width="184" height="12"/> 
       <textElement textAlignment="Center"> 
        <font fontName="Times New Roman" size="10" isBold="true"/> 
       </textElement> 
       <text><![CDATA[DESCRIPTION]]></text> 
      </staticText> 
      <staticText> 
       <reportElement x="234" y="0" width="150" height="12"/> 
       <textElement textAlignment="Center"> 
        <font fontName="Times New Roman" size="10" isBold="true"/> 
       </textElement> 
       <text><![CDATA[SIZE]]></text> 
      </staticText> 
      <staticText> 
       <reportElement x="384" y="0" width="50" height="12"/> 
       <textElement textAlignment="Center"> 
        <font fontName="Times New Roman" size="10" isBold="true"/> 
       </textElement> 
       <text><![CDATA[QTY]]></text> 
      </staticText> 
      <staticText> 
       <reportElement x="434" y="0" width="40" height="12"/> 
       <textElement textAlignment="Center"> 
        <font fontName="Times New Roman" size="10" isBold="true"/> 
       </textElement> 
       <text><![CDATA[UNIT]]></text> 
      </staticText> 
      <staticText> 
       <reportElement x="473" y="0" width="50" height="12"/> 
       <textElement textAlignment="Center"> 
        <font fontName="Times New Roman" isBold="true"/> 
       </textElement> 
       <text><![CDATA[COST]]></text> 
      </staticText> 
      <staticText> 
       <reportElement x="523" y="0" width="50" height="12"/> 
       <textElement textAlignment="Center"> 
        <font fontName="Times New Roman" isBold="true"/> 
       </textElement> 
       <text><![CDATA[AMOUNT]]></text> 
      </staticText> 
      <rectangle> 
       <reportElement mode="Transparent" x="0" y="0" width="50" height="12"/> 
      </rectangle> 
      <rectangle> 
       <reportElement mode="Transparent" x="50" y="0" width="184" height="12"/> 
      </rectangle> 
      <rectangle> 
       <reportElement mode="Transparent" x="234" y="0" width="150" height="12"/> 
      </rectangle> 
      <rectangle> 
       <reportElement mode="Transparent" x="384" y="0" width="50" height="12"/> 
      </rectangle> 
      <rectangle> 
       <reportElement mode="Transparent" x="434" y="0" width="40" height="12"/> 
      </rectangle> 
      <rectangle> 
       <reportElement mode="Transparent" x="474" y="0" width="49" height="12"/> 
      </rectangle> 
      <rectangle> 
       <reportElement mode="Transparent" x="523" y="0" width="50" height="12"/> 
      </rectangle> 
     </band> 
    </columnHeader> 
    <detail> 
     <band height="12" splitType="Stretch"> 
      <textField> 
       <reportElement x="0" y="0" width="50" height="12"/> 
       <textElement textAlignment="Center"> 
        <font fontName="Times New Roman" size="10"/> 
       </textElement> 
       <textFieldExpression><![CDATA[$F{PlantUnit}]]></textFieldExpression> 
      </textField> 
      <textField> 
       <reportElement x="50" y="0" width="184" height="12"/> 
       <textElement textAlignment="Center"> 
        <font fontName="Times New Roman" size="10"/> 
       </textElement> 
       <textFieldExpression><![CDATA[$F{Description}]]></textFieldExpression> 
      </textField> 
      <textField> 
       <reportElement x="234" y="0" width="150" height="12"/> 
       <textElement textAlignment="Center"> 
        <font fontName="Times New Roman" size="10"/> 
       </textElement> 
       <textFieldExpression><![CDATA[$F{Size}]]></textFieldExpression> 
      </textField> 
      <textField> 
       <reportElement x="384" y="0" width="50" height="12"/> 
       <textElement textAlignment="Center"> 
        <font fontName="Times New Roman" size="10"/> 
       </textElement> 
       <textFieldExpression><![CDATA[$F{Qty}]]></textFieldExpression> 
      </textField> 
      <textField> 
       <reportElement x="433" y="0" width="40" height="12"/> 
       <textElement textAlignment="Center"> 
        <font fontName="Times New Roman" size="10"/> 
       </textElement> 
       <textFieldExpression><![CDATA[$F{Unit}]]></textFieldExpression> 
      </textField> 
      <textField> 
       <reportElement x="473" y="0" width="50" height="12"/> 
       <textElement textAlignment="Center"> 
        <font fontName="Times New Roman"/> 
       </textElement> 
       <textFieldExpression><![CDATA[$F{Unit Price}]]></textFieldExpression> 
      </textField> 
      <textField> 
       <reportElement x="523" y="0" width="50" height="12"/> 
       <textElement textAlignment="Center"> 
        <font fontName="Times New Roman"/> 
       </textElement> 
       <textFieldExpression><![CDATA[$F{Amount}]]></textFieldExpression> 
      </textField> 
      <rectangle> 
       <reportElement mode="Transparent" x="0" y="0" width="50" height="12"/> 
      </rectangle> 
      <rectangle> 
       <reportElement mode="Transparent" x="50" y="0" width="184" height="12"/> 
      </rectangle> 
      <rectangle> 
       <reportElement mode="Transparent" x="234" y="0" width="150" height="12"/> 
      </rectangle> 
      <rectangle> 
       <reportElement mode="Transparent" x="384" y="0" width="50" height="12"/> 
      </rectangle> 
      <rectangle> 
       <reportElement mode="Transparent" x="434" y="0" width="40" height="12"/> 
      </rectangle> 
      <rectangle> 
       <reportElement mode="Transparent" x="474" y="0" width="49" height="12"/> 
      </rectangle> 
      <rectangle> 
       <reportElement mode="Transparent" x="523" y="0" width="50" height="12"/> 
      </rectangle> 
     </band> 
    </detail> 
    <columnFooter> 
     <band height="12" splitType="Stretch"> 
      <staticText> 
       <reportElement x="0" y="0" width="100" height="12"/> 
       <textElement> 
        <font fontName="Times New Roman" isBold="true"/> 
       </textElement> 
       <text><![CDATA[Total Amount]]></text> 
      </staticText> 
      <textField isBlankWhenNull="true"> 
       <reportElement x="473" y="0" width="100" height="12"/> 
       <textElement textAlignment="Right"> 
        <font fontName="Times New Roman"/> 
       </textElement> 
       <textFieldExpression><![CDATA[$V{TotalAmount}]]></textFieldExpression> 
      </textField> 
     </band> 
    </columnFooter> 
    <pageFooter> 
     <band height="15" splitType="Stretch"> 
      <textField> 
       <reportElement x="491" y="0" width="56" height="15"/> 
       <textElement textAlignment="Right"> 
        <font fontName="Times New Roman" size="12"/> 
       </textElement> 
       <textFieldExpression><![CDATA["Page "+$V{PAGE_NUMBER}+" of"]]></textFieldExpression> 
      </textField> 
      <textField evaluationTime="Report"> 
       <reportElement x="547" y="0" width="25" height="15"/> 
       <textElement> 
        <font fontName="Times New Roman" size="12"/> 
       </textElement> 
       <textFieldExpression><![CDATA[" " + $V{PAGE_NUMBER}]]></textFieldExpression> 
      </textField> 
     </band> 
    </pageFooter> 
    <summary> 
     <band height="11" splitType="Stretch"/> 
    </summary> 
</jasperReport> 

我们将不胜感激。

+0

thx Darshan Lila进行编辑 – 2014-09-23 05:38:55

+0

[如何在Jaspersoft iReport Designer中对列中的所有值进行求和?](http://stackoverflow.com/questions/13550514/how-to-sum-all-values -in-a-column-in-jaspersoft-ireport-designer) – 2016-07-15 19:51:17

回答

0

您已将amount字段视为字符串。

<field name="Amount" class="java.lang.String"/> 

而你的变量类型也是字符串。

<variable name="TotalAmount" class="java.lang.String" calculation="Sum"> 
     <variableExpression><![CDATA[$F{Amount}]]></variableExpression> 
    </variable> 

你需要有AmountTotalAmount变量是整数,以便碧玉报告能够计算的总和。因此,将其更改为以下:

<field name="Amount" class="java.lang.Integer"/> 

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

Note :如果Amount已经String然后将其转换为Integer再喂到碧玉报告。

+0

我试过这个先生,但出现错误 net.sf.jasperrepots.engine.fill.JRexpressionEVALexception:评估表达式时出错:源文本:$ F {金额} – 2014-09-23 05:51:05

+0

什么是错误? – 2014-09-23 05:51:31

+0

查看我的错误sir Darshan Lila – 2014-09-23 05:59:06