Подтвердить что ты не робот

Группировать несколько полей значений в одну ячейку

Прежде всего, записи отображаются в таблице по компоненту таблицы, но не в отчете.

Результаты выглядят так:

 YEARS MONTHS SUMMONTH SUMQUARTER   
 ----- ------ -------- ----------  
  2009 Jan      130984     432041
       Feb      146503
       Mar      154554     
       Apr      147917     435150 
       May      131822     
       Jun      155411     
       Jul      144000     424806 
       Aug      130369     
       Sep      150437     
       Oct      112137     400114 
       Nov      152057     
       Dec      135920     
 =====================================
       Jan-Dec  1692111
 =====================================
  2010 Jan      139927     417564 
       Feb      154940     
       Mar      122697     
       Apr      163257     413305 
       May      124999     
       Jun      125049     
       Jul      145127     427612 
       Aug      138804     
       Sep      143681     
       Oct      143398     406381 
       Nov      125351     
       Dec      137632     
 =====================================
       Jan-Dec  1664862
 =====================================

В столбце sumquarter отображается сумма каждого квартала за год.

Они не печатаются, когда они повторяют значение поля.

Вопрос заключается в том, как сгруппировать столбец sumquarter, чтобы первое напечатанное повторяющееся значение в каждой строке присоединялось к следующему повторному значению, чтобы стать отдельной ячейкой, пока не встретит не повторяющееся значение?

Вы можете просто увидеть его на изображении. Ниже приведен образ, показанный в таблице, и решение, которое я предпочитаю, состоит в том, чтобы сгруппировать эти 3 месяца суммы в одну ячейку.

Вот изображение:

0bBwX.png

4b9b3361

Ответ 1

Вы можете использовать этот образец:

<?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="year_sum_quarter" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
    <property name="ireport.zoom" value="1.0"/>
    <property name="ireport.x" value="0"/>
    <property name="ireport.y" value="0"/>
    <queryString>
        <![CDATA[]]>
    </queryString>
    <field name="year" class="java.lang.Integer"/>
    <field name="month" class="java.lang.String"/>
    <field name="sum" class="java.lang.Integer"/>
    <field name="q" class="java.lang.Integer"/>
    <variable name="yearSum" class="java.lang.Integer" resetType="Group" resetGroup="yearGroup" calculation="Sum">
        <variableExpression><![CDATA[$F{sum}]]></variableExpression>
    </variable>
    <variable name="qSum" class="java.lang.Integer" resetType="Group" resetGroup="quaterGroup" calculation="Sum">
        <variableExpression><![CDATA[$F{sum}]]></variableExpression>
    </variable>
    <group name="yearGroup">
        <groupExpression><![CDATA[$F{year}]]></groupExpression>
        <groupFooter>
            <band height="20">
                <textField>
                    <reportElement x="100" y="0" width="100" height="20"/>
                    <box leftPadding="10">
                        <topPen lineWidth="1.0"/>
                        <leftPen lineWidth="0.0"/>
                        <bottomPen lineWidth="1.0"/>
                        <rightPen lineWidth="0.0"/>
                    </box>
                    <textElement/>
                    <textFieldExpression><![CDATA["Jan-Dec, " + $F{year}]]></textFieldExpression>
                </textField>
                <textField>
                    <reportElement x="200" y="0" width="100" height="20"/>
                    <box leftPadding="0">
                        <topPen lineWidth="1.0"/>
                        <leftPen lineWidth="0.0"/>
                        <bottomPen lineWidth="1.0"/>
                        <rightPen lineWidth="0.0"/>
                    </box>
                    <textElement/>
                    <textFieldExpression><![CDATA[$V{yearSum}]]></textFieldExpression>
                </textField>
                <staticText>
                    <reportElement x="0" y="0" width="100" height="20"/>
                    <box>
                        <topPen lineWidth="1.0"/>
                        <leftPen lineWidth="1.0"/>
                        <bottomPen lineWidth="1.0"/>
                        <rightPen lineWidth="0.0"/>
                    </box>
                    <textElement textAlignment="Center" verticalAlignment="Middle">
                        <font isBold="true" isItalic="true"/>
                    </textElement>
                    <text><![CDATA[]]></text>
                </staticText>
                <staticText>
                    <reportElement x="300" y="0" width="100" height="20"/>
                    <box>
                        <topPen lineWidth="1.0"/>
                        <leftPen lineWidth="0.0"/>
                        <bottomPen lineWidth="1.0"/>
                        <rightPen lineWidth="1.0"/>
                    </box>
                    <textElement textAlignment="Center" verticalAlignment="Middle">
                        <font isBold="true" isItalic="true"/>
                    </textElement>
                    <text><![CDATA[]]></text>
                </staticText>
            </band>
        </groupFooter>
    </group>
    <group name="quaterGroup">
        <groupExpression><![CDATA[$F{year} + $F{q}]]></groupExpression>
    </group>
    <columnHeader>
        <band height="50">
            <staticText>
                <reportElement x="100" y="30" width="100" height="20"/>
                <box>
                    <topPen lineWidth="1.0"/>
                    <leftPen lineWidth="1.0"/>
                    <bottomPen lineWidth="1.0"/>
                    <rightPen lineWidth="1.0"/>
                </box>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font isBold="true" isItalic="true"/>
                </textElement>
                <text><![CDATA[Month]]></text>
            </staticText>
            <staticText>
                <reportElement x="0" y="30" width="100" height="20"/>
                <box>
                    <topPen lineWidth="1.0"/>
                    <leftPen lineWidth="1.0"/>
                    <bottomPen lineWidth="1.0"/>
                    <rightPen lineWidth="1.0"/>
                </box>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font isBold="true" isItalic="true"/>
                </textElement>
                <text><![CDATA[Year]]></text>
            </staticText>
            <staticText>
                <reportElement x="200" y="30" width="100" height="20"/>
                <box>
                    <topPen lineWidth="1.0"/>
                    <leftPen lineWidth="1.0"/>
                    <bottomPen lineWidth="1.0"/>
                    <rightPen lineWidth="1.0"/>
                </box>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font isBold="true" isItalic="true"/>
                </textElement>
                <text><![CDATA[Month Sum]]></text>
            </staticText>
            <staticText>
                <reportElement x="300" y="30" width="100" height="20"/>
                <box>
                    <topPen lineWidth="1.0"/>
                    <leftPen lineWidth="1.0"/>
                    <bottomPen lineWidth="1.0"/>
                    <rightPen lineWidth="1.0"/>
                </box>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font isBold="true" isItalic="true"/>
                </textElement>
                <text><![CDATA[Quarter Sum]]></text>
            </staticText>
        </band>
    </columnHeader>
    <detail>
        <band height="20" splitType="Stretch">
            <staticText>
                <reportElement x="300" y="0" width="100" height="20"/>
                <box>
                    <topPen lineWidth="0.0"/>
                    <leftPen lineWidth="1.0"/>
                    <bottomPen lineWidth="0.0"/>
                    <rightPen lineWidth="1.0"/>
                </box>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font isBold="true" isItalic="true"/>
                </textElement>
                <text><![CDATA[]]></text>
            </staticText>
            <staticText>
                <reportElement x="0" y="0" width="100" height="20"/>
                <box>
                    <topPen lineWidth="0.0"/>
                    <leftPen lineWidth="1.0"/>
                    <bottomPen lineWidth="0.0"/>
                    <rightPen lineWidth="1.0"/>
                </box>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font isBold="true" isItalic="true"/>
                </textElement>
                <text><![CDATA[]]></text>
            </staticText>
            <textField>
                <reportElement x="0" y="0" width="100" height="20">
                    <printWhenExpression><![CDATA[$V{yearGroup_COUNT} == 1]]></printWhenExpression>
                </reportElement>
                <box leftPadding="10">
                    <topPen lineWidth="0.0"/>
                    <leftPen lineWidth="1.0"/>
                    <bottomPen lineWidth="0.0"/>
                    <rightPen lineWidth="1.0"/>
                </box>
                <textElement/>
                <textFieldExpression><![CDATA[$F{year}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="200" y="0" width="100" height="20"/>
                <box leftPadding="10">
                    <topPen lineWidth="1.0"/>
                    <leftPen lineWidth="1.0"/>
                    <bottomPen lineWidth="1.0"/>
                    <rightPen lineWidth="1.0"/>
                </box>
                <textElement/>
                <textFieldExpression><![CDATA[$F{sum}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="100" y="0" width="100" height="20"/>
                <box leftPadding="10">
                    <topPen lineWidth="1.0"/>
                    <leftPen lineWidth="1.0"/>
                    <bottomPen lineWidth="1.0"/>
                    <rightPen lineWidth="1.0"/>
                </box>
                <textElement/>
                <textFieldExpression><![CDATA[$F{month}]]></textFieldExpression>
            </textField>
            <textField evaluationTime="Group" evaluationGroup="quaterGroup" isBlankWhenNull="false">
                <reportElement stretchType="RelativeToBandHeight" isPrintRepeatedValues="false" x="300" y="0" width="100" height="20" printWhenGroupChanges="quaterGroup">
                    <printWhenExpression><![CDATA[$V{quaterGroup_COUNT} == 1]]></printWhenExpression>
                </reportElement>
                <box leftPadding="10">
                    <topPen lineWidth="0.0"/>
                    <leftPen lineWidth="1.0"/>
                    <bottomPen lineWidth="0.0"/>
                    <rightPen lineWidth="1.0"/>
                </box>
                <textElement/>
                <textFieldExpression><![CDATA[$V{qSum}]]></textFieldExpression>
            </textField>
            <line>
                <reportElement x="300" y="0" width="100" height="1" printWhenGroupChanges="quaterGroup">
                    <printWhenExpression><![CDATA[$V{quaterGroup_COUNT} == 1]]></printWhenExpression>
                </reportElement>
            </line>
        </band>
    </detail>
</jasperReport>

Результат будет (в формате pdf): Resulting report in PDF format

В этом примере я использовал два элемента в полосе Detail для столбца Year: один textField с только вертикальными границами и с свойством printWhenExpression: "$V{yearGroup_COUNT} == 1" (я показываю его только один раз для всей годгруппы) и один staticText без какого-либо текста и с только вертикальными границами.

Я использовал три элемента в диапазоне Detail для столбца Quarter Sum:
один textField с только вертикальными границами и с printWhenExpression: "$V{quaterGroup_COUNT} == 1" (я показываю его только один раз для всей quaterGroup), один staticText без какого-либо текста и с только вертикальными границами и элементом line для рисования горизонтальной границы с printWhenExpression: "$V{quaterGroup_COUNT} == 1".