首页 > 解决方案 > 如何创建具有内行的表

问题描述

如何在jasper中获得这种情况(将最后一列移动为新的动态行)? 在此处输入图像描述

Jrxml代码:https ://pastebin.com/sMa1Cct2

<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.8.0.final utlizzo versione della libreria JasperReports6.8.0-2ed8dfabb690ff337a5797129f2cd92902b0c87b  -->
<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="template_Table" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="1a0aa80b-dc07-4dca-bdbc-aa78eeb0d12b">
    <style name="Table_TH" mode="Opaque" backcolor="#F0F8FF">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
            <topPen lineWidth="0.5" lineColor="#000000"/>
            <leftPen lineWidth="0.5" lineColor="#000000"/>
            <bottomPen lineWidth="0.5" lineColor="#000000"/>
            <rightPen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <style name="Table_CH" mode="Opaque" backcolor="#BFE1FF">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
            <topPen lineWidth="0.5" lineColor="#000000"/>
            <leftPen lineWidth="0.5" lineColor="#000000"/>
            <bottomPen lineWidth="0.5" lineColor="#000000"/>
            <rightPen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <style name="Table_TD" mode="Opaque" backcolor="#FFFFFF">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
            <topPen lineWidth="0.5" lineColor="#000000"/>
            <leftPen lineWidth="0.5" lineColor="#000000"/>
            <bottomPen lineWidth="0.5" lineColor="#000000"/>
            <rightPen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <subDataset name="ItemDataset" uuid="2914f7c6-c2d7-448b-b0c1-090970e18ed6">
        <queryString>
            <![CDATA[]]>
        </queryString>
        <field name="descrizione" class="java.lang.String"/>
        <field name="numero_depositanti" class="java.lang.String"/>
        <field name="quantita" class="java.lang.String"/>
        <field name="percentuale" class="java.lang.String"/>
        <field name="conti" class="java.util.List"/>
        <group name="Group1"/>
    </subDataset>
    <parameter name="ItemDataSource" class="net.sf.jasperreports.engine.data.JRBeanCollectionDataSource"/>
    <queryString>
        <![CDATA[]]>
    </queryString>
    <background>
        <band splitType="Stretch"/>
    </background>
    <detail>
        <band height="256" splitType="Stretch">
            <componentElement>
                <reportElement x="0" y="0" width="555" height="200" uuid="7786bb05-503a-4b6a-991a-a7bcf3abad07">
                    <property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.VerticalRowLayout"/>
                </reportElement>
                <jr:table xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd">
                    <datasetRun subDataset="ItemDataset" uuid="d3e1e03a-2c83-4436-9e50-79518bc3d337">
                        <dataSourceExpression><![CDATA[$P{ItemDataSource}]]></dataSourceExpression>
                    </datasetRun>
                    <jr:column width="75" uuid="dca8961f-ce2d-47ac-879c-b15847d170a9">
                        <property name="com.jaspersoft.studio.components.table.model.column.name" value="Colonna1"/>
                        <jr:tableHeader height="30" rowSpan="1">
                            <staticText>
                                <reportElement x="0" y="0" width="75" height="30" uuid="f60d1675-6fb6-4569-93ca-de32b3a8e861"/>
                                <text><![CDATA[Descrizione]]></text>
                            </staticText>
                        </jr:tableHeader>
                        <jr:detailCell height="30">
                            <textField>
                                <reportElement x="0" y="0" width="75" height="30" uuid="f1de366a-b36f-4200-9b1e-7a0009be5373"/>
                                <textFieldExpression><![CDATA[$F{descrizione}]]></textFieldExpression>
                            </textField>
                        </jr:detailCell>
                    </jr:column>
                    <jr:column width="140" uuid="980fffb5-1088-47a6-b00f-b5d08b7093c9">
                        <property name="com.jaspersoft.studio.components.table.model.column.name" value="Colonna2"/>
                        <jr:tableHeader height="30" rowSpan="1">
                            <staticText>
                                <reportElement x="0" y="0" width="140" height="30" uuid="16679b95-2e6e-4ca1-b8b6-dd7b74267c56"/>
                                <text><![CDATA[Numero depositanti]]></text>
                            </staticText>
                        </jr:tableHeader>
                        <jr:detailCell height="30">
                            <textField>
                                <reportElement x="0" y="0" width="140" height="30" uuid="341e7faf-9680-4941-a9a4-ac78b8f4aae0"/>
                                <textFieldExpression><![CDATA[$F{numero_depositanti}]]></textFieldExpression>
                            </textField>
                        </jr:detailCell>
                    </jr:column>
                    <jr:column width="100" uuid="980fffb5-1088-47a6-b00f-b5d08b7093c9">
                        <property name="com.jaspersoft.studio.components.table.model.column.name" value="Colonna3"/>
                        <jr:tableHeader height="30" rowSpan="1">
                            <staticText>
                                <reportElement x="0" y="0" width="100" height="30" uuid="16679b95-2e6e-4ca1-b8b6-dd7b74267c56"/>
                                <text><![CDATA[Quantita]]></text>
                            </staticText>
                        </jr:tableHeader>
                        <jr:detailCell height="30">
                            <textField>
                                <reportElement x="0" y="0" width="100" height="30" uuid="341e7faf-9680-4941-a9a4-ac78b8f4aae0"/>
                                <textFieldExpression><![CDATA[$F{quantita}]]></textFieldExpression>
                            </textField>
                        </jr:detailCell>
                    </jr:column>
                    <jr:column width="100" uuid="980fffb5-1088-47a6-b00f-b5d08b7093c9">
                        <property name="com.jaspersoft.studio.components.table.model.column.name" value="Colonna4"/>
                        <jr:tableHeader height="30" rowSpan="1">
                            <staticText>
                                <reportElement x="0" y="0" width="100" height="30" uuid="16679b95-2e6e-4ca1-b8b6-dd7b74267c56"/>
                                <text><![CDATA[Percentuale]]></text>
                            </staticText>
                        </jr:tableHeader>
                        <jr:detailCell height="30">
                            <textField>
                                <reportElement x="0" y="0" width="100" height="30" uuid="341e7faf-9680-4941-a9a4-ac78b8f4aae0"/>
                                <textFieldExpression><![CDATA[$F{percentuale}]]></textFieldExpression>
                            </textField>
                        </jr:detailCell>
                    </jr:column>
                    <jr:column width="140" uuid="980fffb5-1088-47a6-b00f-b5d08b7093c9">
                        <property name="com.jaspersoft.studio.components.table.model.column.name" value="Colonna5"/>
                        <jr:tableHeader height="30" rowSpan="1">
                            <staticText>
                                <reportElement x="0" y="0" width="140" height="30" uuid="16679b95-2e6e-4ca1-b8b6-dd7b74267c56"/>
                                <text><![CDATA[Percentuale]]></text>
                            </staticText>
                        </jr:tableHeader>
                        <jr:detailCell height="30">
                            <textField>
                                <reportElement x="0" y="0" width="140" height="30" uuid="341e7faf-9680-4941-a9a4-ac78b8f4aae0"/>
                                <textFieldExpression><![CDATA[$F{conti}]]></textFieldExpression>
                            </textField>
                        </jr:detailCell>
                    </jr:column>
                </jr:table>
            </componentElement>
        </band>
        <band height="50">
            <staticText>
                <reportElement x="0" y="0" width="75" height="20" backcolor="#151515" uuid="3316e9fe-e7e7-4020-84d6-a8f16cd8eb6b"/>
                <text><![CDATA[descrizione]]></text>
            </staticText>
            <staticText>
                <reportElement x="151" y="0" width="100" height="20" uuid="3316e9fe-e7e7-4020-84d6-a8f16cd8eb68"/>
                <text><![CDATA[quantita]]></text>
            </staticText>
            <staticText>
                <reportElement x="226" y="0" width="75" height="20" uuid="3316e9fe-e7e7-4020-84d6-a8f16cd8eb69"/>
                <text><![CDATA[percentuale]]></text>
            </staticText>
        </band>
    </detail>
</jasperReport>

标签: jasper-reports

解决方案


我看到的唯一选择是,您必须创建一个只有这个属性的新表。然后您可以将其布局为看起来像一张桌子:

<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.5.1.final using JasperReports Library version 6.5.1  -->
<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="template_Table" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="1a0aa80b-dc07-4dca-bdbc-aa78eeb0d12b">
    <style name="Table_TH" mode="Opaque" backcolor="#F0F8FF">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
            <topPen lineWidth="0.5" lineColor="#000000"/>
            <leftPen lineWidth="0.5" lineColor="#000000"/>
            <bottomPen lineWidth="0.5" lineColor="#000000"/>
            <rightPen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <style name="Table_CH" mode="Opaque" backcolor="#BFE1FF">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
            <topPen lineWidth="0.5" lineColor="#000000"/>
            <leftPen lineWidth="0.5" lineColor="#000000"/>
            <bottomPen lineWidth="0.5" lineColor="#000000"/>
            <rightPen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <style name="Table_TD" mode="Opaque" backcolor="#FFFFFF">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
            <topPen lineWidth="0.5" lineColor="#000000"/>
            <leftPen lineWidth="0.5" lineColor="#000000"/>
            <bottomPen lineWidth="0.5" lineColor="#000000"/>
            <rightPen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <subDataset name="ItemDataset" uuid="2914f7c6-c2d7-448b-b0c1-090970e18ed6">
        <queryString>
            <![CDATA[]]>
        </queryString>
        <field name="descrizione" class="java.lang.String"/>
        <field name="numero_depositanti" class="java.lang.String"/>
        <field name="quantita" class="java.lang.String"/>
        <field name="percentuale" class="java.lang.String"/>
        <field name="conti" class="java.util.List"/>
        <group name="Group1"/>
    </subDataset>
    <parameter name="ItemDataSource" class="net.sf.jasperreports.engine.data.JRBeanCollectionDataSource"/>
    <queryString>
        <![CDATA[]]>
    </queryString>
    <background>
        <band splitType="Stretch"/>
    </background>
    <detail>
        <band height="256" splitType="Stretch">
            <componentElement>
                <reportElement x="0" y="0" width="555" height="60" uuid="7786bb05-503a-4b6a-991a-a7bcf3abad07">
                    <property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.VerticalRowLayout"/>
                </reportElement>
                <jr:table xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd">
                    <datasetRun subDataset="ItemDataset" uuid="d3e1e03a-2c83-4436-9e50-79518bc3d337">
                        <dataSourceExpression><![CDATA[$P{ItemDataSource}]]></dataSourceExpression>
                    </datasetRun>
                    <jr:column width="75" uuid="dca8961f-ce2d-47ac-879c-b15847d170a9">
                        <property name="com.jaspersoft.studio.components.table.model.column.name" value="Column1"/>
                        <jr:tableHeader height="30" rowSpan="1">
                            <staticText>
                                <reportElement x="0" y="0" width="75" height="30" uuid="f60d1675-6fb6-4569-93ca-de32b3a8e861"/>
                                <text><![CDATA[Descrizione]]></text>
                            </staticText>
                        </jr:tableHeader>
                        <jr:detailCell height="30">
                            <textField>
                                <reportElement x="0" y="0" width="75" height="30" uuid="f1de366a-b36f-4200-9b1e-7a0009be5373"/>
                                <textFieldExpression><![CDATA[$F{descrizione}]]></textFieldExpression>
                            </textField>
                        </jr:detailCell>
                    </jr:column>
                    <jr:column width="140" uuid="980fffb5-1088-47a6-b00f-b5d08b7093c9">
                        <property name="com.jaspersoft.studio.components.table.model.column.name" value="Column2"/>
                        <jr:tableHeader height="30" rowSpan="1">
                            <staticText>
                                <reportElement x="0" y="0" width="140" height="30" uuid="16679b95-2e6e-4ca1-b8b6-dd7b74267c56"/>
                                <text><![CDATA[Numero depositanti]]></text>
                            </staticText>
                        </jr:tableHeader>
                        <jr:detailCell height="30">
                            <textField>
                                <reportElement x="0" y="0" width="140" height="30" uuid="341e7faf-9680-4941-a9a4-ac78b8f4aae0"/>
                                <textFieldExpression><![CDATA[$F{numero_depositanti}]]></textFieldExpression>
                            </textField>
                        </jr:detailCell>
                    </jr:column>
                    <jr:column width="100" uuid="980fffb5-1088-47a6-b00f-b5d08b7093c9">
                        <property name="com.jaspersoft.studio.components.table.model.column.name" value="Column3"/>
                        <jr:tableHeader height="30" rowSpan="1">
                            <staticText>
                                <reportElement x="0" y="0" width="100" height="30" uuid="16679b95-2e6e-4ca1-b8b6-dd7b74267c56"/>
                                <text><![CDATA[Quantita]]></text>
                            </staticText>
                        </jr:tableHeader>
                        <jr:detailCell height="30">
                            <textField>
                                <reportElement x="0" y="0" width="100" height="30" uuid="341e7faf-9680-4941-a9a4-ac78b8f4aae0"/>
                                <textFieldExpression><![CDATA[$F{quantita}]]></textFieldExpression>
                            </textField>
                        </jr:detailCell>
                    </jr:column>
                    <jr:column width="105" uuid="980fffb5-1088-47a6-b00f-b5d08b7093c9">
                        <property name="com.jaspersoft.studio.components.table.model.column.name" value="Column4"/>
                        <jr:tableHeader height="30" rowSpan="1">
                            <staticText>
                                <reportElement x="0" y="0" width="105" height="30" uuid="16679b95-2e6e-4ca1-b8b6-dd7b74267c56"/>
                                <text><![CDATA[Percentuale]]></text>
                            </staticText>
                        </jr:tableHeader>
                        <jr:detailCell height="30">
                            <textField>
                                <reportElement x="0" y="0" width="105" height="30" uuid="341e7faf-9680-4941-a9a4-ac78b8f4aae0"/>
                                <textFieldExpression><![CDATA[$F{percentuale}]]></textFieldExpression>
                            </textField>
                        </jr:detailCell>
                    </jr:column>
                    <jr:column width="140" uuid="980fffb5-1088-47a6-b00f-b5d08b7093c9">
                        <property name="com.jaspersoft.studio.components.table.model.column.name" value="Column2"/>
                        <jr:tableHeader height="30" rowSpan="1"/>
                        <jr:detailCell height="30"/>
                    </jr:column>
                </jr:table>
            </componentElement>
            <componentElement>
                <reportElement x="0" y="60" width="555" height="30" uuid="05eb78da-89c1-4af6-bdad-79a3b8ca819d">
                    <property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.VerticalRowLayout"/>
                </reportElement>
                <jr:table xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd">
                    <datasetRun subDataset="ItemDataset" uuid="c27bd785-53a9-4bcc-a1cc-3950f707d796">
                        <dataSourceExpression><![CDATA[$P{ItemDataSource}]]></dataSourceExpression>
                    </datasetRun>
                    <jr:column width="75" uuid="7b446ae4-9502-48e3-afd5-6957e705f284">
                        <property name="com.jaspersoft.studio.components.table.model.column.name" value="Column1"/>
                        <jr:detailCell height="30"/>
                    </jr:column>
                    <jr:column width="345" uuid="06c2486d-3e7c-4b64-9282-e1c58541e69c">
                        <property name="com.jaspersoft.studio.components.table.model.column.name" value="Column2"/>
                        <jr:detailCell height="30">
                            <textField>
                                <reportElement x="0" y="0" width="345" height="30" uuid="8a99019f-ad26-4182-ad81-e61b356dcefe"/>
                                <textFieldExpression><![CDATA[$F{conti}]]></textFieldExpression>
                            </textField>
                        </jr:detailCell>
                    </jr:column>
                </jr:table>
            </componentElement>
        </band>
        <band height="50">
            <staticText>
                <reportElement x="0" y="0" width="75" height="20" backcolor="#151515" uuid="3316e9fe-e7e7-4020-84d6-a8f16cd8eb6b"/>
                <text><![CDATA[descrizione]]></text>
            </staticText>
            <staticText>
                <reportElement x="151" y="0" width="100" height="20" uuid="3316e9fe-e7e7-4020-84d6-a8f16cd8eb68"/>
                <text><![CDATA[quantita]]></text>
            </staticText>
            <staticText>
                <reportElement x="226" y="0" width="75" height="20" uuid="3316e9fe-e7e7-4020-84d6-a8f16cd8eb69"/>
                <text><![CDATA[percentuale]]></text>
            </staticText>
        </band>
    </detail>
</jasperReport>

推荐阅读