当前位置: 首页 > 知识库问答 >
问题:

如何在多列中拆分详细信息,同时以编程方式为后续节追加“continuation”消息?

艾灿
2023-03-14

如果动态大小不适合当前列,我有一个客户请求将个人信息(姓名、地址、次要地址等)的详细信息拆分到多个列中。需要注意的是,name字段后跟单词'(continure)',作为后续列中段的标题。

这可能吗?如果可能,对这种情况有什么创造性解决方案的建议吗?

此外,还会出现一种奇怪的行为,如果一个详细信息在多个列中拆分,则详细信息的第一部分(直到subreport元素)会在下一列中重复。这种行为对客户来说也是不可取的,需要进行调整,以便没有任何东西(除了标题)是重复的。

这是客户需要的语法:

Name 1                              Name 2
Address 1                           (Continued)
City 1                              AL – Address 3
State 1                             AL - City 3
Zip 1                               AL - State 3
Additional Locations:               AL - Zip 3
AL-Address 1                        ...
AL-City 1
AL-State 1
AL-Zip 1
AL-Address 2
AL-City 2
AL-State 2
AL-Zip 2

Name 2
Address 2
City 2
State 2
Zip 2
Additional Locations:
AL-Address 1
AL – City 1
AL-State 1
AL – Zip 1
AL – Address 2
AL – City 2
AL – State 2
AL – Zip 2
Name1                    Name1
Address1                 Address1
City1                    City1
State1                   State1
Zip1                     Zip1
Additional Locations     Additional Locations
AL-Name1                 AL-City2
AL-Address1              AL-State2
AL-City1                 AL-State2
AL-State1
AL-Zip1
AL-Name2
AL-Address2
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.3.1.final using JasperReports Library version 6.3.1  -->
<!-- 2017-06-22T09:48:08 -->
<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="Blank_A4" columnCount="2" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" scriptletClass="path.to.my.scriptlet" uuid="af53d807-7975-4ff7-bfc5-e438944aa795">
    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
    <queryString>
        <![CDATA[]]>
    </queryString>
    <field name="Name" class="java.lang.String"/>
    <field name="Address" class="java.lang.String"/>
    <field name="City" class="java.lang.String"/>
    <field name="State" class="java.lang.String"/>
    <field name="Zip" class="java.lang.String"/>
    <field name="AdditionalLocations" class="java.util.List"/>
    <variable name="IN_MIDDLE_OF_DETAIL" class="java.lang.Boolean" calculation="System">
        <initialValueExpression><![CDATA[Boolean.False]]></initialValueExpression>
    </variable>
    <columnHeader>
        <band height="74" splitType="Stretch">
            <textField isBlankWhenNull="true">
                <reportElement x="-10" y="0" width="100" height="30" uuid="258dce49-fb61-4887-bb30-69e80e96d8f1">
                    <printWhenExpression><![CDATA[$V{IN_MIDDLE_OF_DETAIL}]]></printWhenExpression>
                </reportElement>
                <textFieldExpression><![CDATA[$F{Name}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="-10" y="40" width="100" height="30" uuid="c18b2fab-900b-4641-aaef-2520510a3510">
                    <printWhenExpression><![CDATA[$V{IN_MIDDLE_OF_DETAIL}]]></printWhenExpression>
                </reportElement>
                <textFieldExpression><![CDATA["(CONTINUED)"]]></textFieldExpression>
            </textField>
        </band>
    </columnHeader>
    <detail>
        <band height="426" splitType="Stretch">
            <textField>
                <reportElement x="0" y="10" width="100" height="30" uuid="853a1b0d-a49e-45c4-8183-83cfd69bf5af"/>
                <textFieldExpression><![CDATA[$F{Name}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="0" y="50" width="100" height="30" uuid="46697c6d-1c2f-422b-9170-6b2f36ce13ba"/>
                <textFieldExpression><![CDATA[$F{Address}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="0" y="90" width="100" height="30" uuid="31730cd5-0b17-452e-8a22-d16ea2061605"/>
                <textFieldExpression><![CDATA[$F{City}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="0" y="120" width="100" height="30" uuid="b4a4c671-dc63-41b4-b080-9ad5b750bb58"/>
                <textFieldExpression><![CDATA[$F{State}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="0" y="160" width="100" height="30" uuid="8f8bec7c-3d4a-466b-8b02-2bb82e61904d"/>
                <textFieldExpression><![CDATA[$F{Zip}]]></textFieldExpression>
            </textField>
            <subreport>
                <reportElement x="0" y="220" width="100" height="110" uuid="8ef583fd-fa23-47d8-80d0-90de4f6478a0"/>
                <dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{AdditionalLocations})]]></dataSourceExpression>
                <subreportExpression><![CDATA["Blank_A4_1.jasper"]]></subreportExpression>
            </subreport>
            <staticText>
                <reportElement x="10" y="198" width="100" height="30" uuid="4887e0c1-3da2-4350-9454-4a3e33c0fe71"/>
                <text><![CDATA[Additional Locations]]></text>
            </staticText>
        </band>
    </detail>
</jasperReport>
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.3.1.final using JasperReports Library version 6.3.1  -->
<!-- 2017-06-22T10:39:43 -->
<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="Blank_A4_1" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="9b8a1d93-2ee6-4d29-b9ec-7c56a3917729">
    <queryString>
        <![CDATA[]]>
    </queryString>
    <field name="Address" class="java.lang.String"/>
    <field name="City" class="java.lang.String"/>
    <field name="State" class="java.lang.String"/>
    <field name="Zip" class="java.lang.String"/>
    <detail>
        <band height="168" splitType="Stretch">
            <textField isBlankWhenNull="true">
                <reportElement x="0" y="10" width="100" height="30" uuid="3d74e624-6b6f-40e9-87d2-ddb5022668b2"/>
                <textFieldExpression><![CDATA[$F{Address}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="0" y="50" width="100" height="30" uuid="5df31fa3-38ee-44a4-8931-e8eef45fb7a6"/>
                <textFieldExpression><![CDATA[$F{City}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="0" y="89" width="100" height="30" uuid="964a282f-54c7-44a3-954d-27d1c70d3d0c"/>
                <textFieldExpression><![CDATA[$F{State}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="0" y="130" width="100" height="30" uuid="e1349222-d945-4dec-8454-e2d6e3fb6a2a"/>
                <textFieldExpression><![CDATA[$F{Zip}]]></textFieldExpression>
            </textField>
        </band>
    </detail>
</jasperReport>
@Override
public void beforeDetailEval() throws JRScriptletException
{
    setVariableValue("IN_MIDDLE_OF_DETAIL", Boolean.TRUE)
}


@Override
public void afterDetailEval() throws JRScriptletException
{
    setVariableValue("IN_MIDDLE_OF_DETAIL", Boolean.FALSE)
}

共有1个答案

瞿博易
2023-03-14

删除scriptlet,没有必要这样做,让我们使用这样一个事实:子报表有自己的页计数,因此当它在主报表中中断时,它会计数一个页

我将使用的解决方案是子报表中的pageheader带,页码(>1)上有printwhenexpression

这意味着当子报表拆分到新“页”(名称和“继续”)时要显示的文本将进入子报表的pageheader中,并且应该打印在除第一页以外的所有子报表“页”上。

<pageHeader>
    <band height="44">
    <printWhenExpression><![CDATA[$V{PAGE_NUMBER}>1]]></printWhenExpression>
    <textField>
        <reportElement x="0" y="0" width="220" height="20" uuid="8cce4cab-6ccf-4ddb-b1f1-508dc97bfcfe"/>
        <textElement verticalAlignment="Middle">
            <font isBold="true"/>
        </textElement>
        <textFieldExpression><![CDATA[$P{name}]]></textFieldExpression>
    </textField>
    <textField>
        <reportElement x="0" y="20" width="220" height="19" uuid="c18b2fab-900b-4641-aaef-2520510a3510"/>
        <textElement verticalAlignment="Middle">
            <font isItalic="true"/>
        </textElement>
        <textFieldExpression><![CDATA["(Continued)"]]></textFieldExpression>
    </textField>
</band>
</pageHeader>

示例输出

我已降低页面高度以减少图像

**main report jrxml**

<?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="Blank_A4" columnCount="2" pageWidth="595" pageHeight="500" columnWidth="277" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="af53d807-7975-4ff7-bfc5-e438944aa795">
	<queryString>
		<![CDATA[]]>
	</queryString>
	<field name="name" class="java.lang.String"/>
	<field name="address" class="java.lang.String"/>
	<field name="city" class="java.lang.String"/>
	<field name="state" class="java.lang.String"/>
	<field name="zip" class="java.lang.String"/>
	<field name="additionalLocations" class="java.util.List"/>
	<detail>
		<band height="141" splitType="Immediate">
			<textField isStretchWithOverflow="true">
				<reportElement x="0" y="20" width="280" height="20" uuid="46697c6d-1c2f-422b-9170-6b2f36ce13ba">
					<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
				</reportElement>
				<textElement verticalAlignment="Middle"/>
				<textFieldExpression><![CDATA[$F{address}]]></textFieldExpression>
			</textField>
			<textField isStretchWithOverflow="true">
				<reportElement x="0" y="40" width="280" height="20" uuid="31730cd5-0b17-452e-8a22-d16ea2061605"/>
				<textElement verticalAlignment="Middle"/>
				<textFieldExpression><![CDATA[$F{city}]]></textFieldExpression>
			</textField>
			<textField isStretchWithOverflow="true">
				<reportElement x="0" y="60" width="280" height="20" uuid="b4a4c671-dc63-41b4-b080-9ad5b750bb58"/>
				<textElement verticalAlignment="Middle"/>
				<textFieldExpression><![CDATA[$F{state}]]></textFieldExpression>
			</textField>
			<textField isStretchWithOverflow="true">
				<reportElement x="0" y="80" width="280" height="20" uuid="8f8bec7c-3d4a-466b-8b02-2bb82e61904d"/>
				<textElement verticalAlignment="Middle"/>
				<textFieldExpression><![CDATA[$F{zip}]]></textFieldExpression>
			</textField>
			<subreport>
				<reportElement x="0" y="120" width="280" height="20" isPrintWhenDetailOverflows="true" uuid="8ef583fd-fa23-47d8-80d0-90de4f6478a0"/>
				<subreportParameter name="name">
					<subreportParameterExpression><![CDATA[$F{name}]]></subreportParameterExpression>
				</subreportParameter>
				<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{additionalLocations})]]></dataSourceExpression>
				<subreportExpression><![CDATA["C:/Users/pette/JaspersoftWorkspace/MyReports/SplitSubreport.jasper"]]></subreportExpression>
			</subreport>
			<staticText>
				<reportElement x="0" y="100" width="280" height="20" uuid="4887e0c1-3da2-4350-9454-4a3e33c0fe71"/>
				<textElement verticalAlignment="Middle">
					<font isItalic="false" isUnderline="true"/>
				</textElement>
				<text><![CDATA[Additional Locations]]></text>
			</staticText>
			<textField isStretchWithOverflow="true" isBlankWhenNull="true">
				<reportElement x="0" y="0" width="280" height="20" uuid="258dce49-fb61-4887-bb30-69e80e96d8f1"/>
				<textElement verticalAlignment="Middle">
					<font isBold="true"/>
				</textElement>
				<textFieldExpression><![CDATA[$F{name}]]></textFieldExpression>
			</textField>
		</band>
	</detail>
</jasperReport>

**subreport jrxml**

<?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="Blank_A4_1" pageWidth="280" pageHeight="200" columnWidth="280" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" uuid="9b8a1d93-2ee6-4d29-b9ec-7c56a3917729">
	<parameter name="name" class="java.lang.String"/>
	<queryString>
		<![CDATA[]]>
	</queryString>
	<field name="address" class="java.lang.String"/>
	<field name="city" class="java.lang.String"/>
	<field name="state" class="java.lang.String"/>
	<field name="zip" class="java.lang.String"/>
	<pageHeader>
		<band height="44">
			<printWhenExpression><![CDATA[$V{PAGE_NUMBER}>1]]></printWhenExpression>
			<textField>
				<reportElement x="0" y="20" width="220" height="19" uuid="c18b2fab-900b-4641-aaef-2520510a3510"/>
				<textElement verticalAlignment="Middle">
					<font isItalic="true"/>
				</textElement>
				<textFieldExpression><![CDATA["(Continued)"]]></textFieldExpression>
			</textField>
			<textField>
				<reportElement x="0" y="0" width="220" height="20" uuid="8cce4cab-6ccf-4ddb-b1f1-508dc97bfcfe"/>
				<textElement verticalAlignment="Middle">
					<font isBold="true"/>
				</textElement>
				<textFieldExpression><![CDATA[$P{name}]]></textFieldExpression>
			</textField>
		</band>
	</pageHeader>
	<detail>
		<band height="85" splitType="Stretch">
			<textField isStretchWithOverflow="true" isBlankWhenNull="true">
				<reportElement x="0" y="-1" width="220" height="21" uuid="3d74e624-6b6f-40e9-87d2-ddb5022668b2"/>
				<textElement verticalAlignment="Middle"/>
				<textFieldExpression><![CDATA[$F{address}]]></textFieldExpression>
			</textField>
			<textField isStretchWithOverflow="true">
				<reportElement x="0" y="20" width="220" height="20" uuid="5df31fa3-38ee-44a4-8931-e8eef45fb7a6"/>
				<textElement verticalAlignment="Middle"/>
				<textFieldExpression><![CDATA[$F{city}]]></textFieldExpression>
			</textField>
			<textField isStretchWithOverflow="true">
				<reportElement x="0" y="40" width="220" height="20" uuid="964a282f-54c7-44a3-954d-27d1c70d3d0c"/>
				<textElement verticalAlignment="Middle"/>
				<textFieldExpression><![CDATA[$F{state}]]></textFieldExpression>
			</textField>
			<textField isStretchWithOverflow="true">
				<reportElement x="0" y="60" width="220" height="20" uuid="e1349222-d945-4dec-8454-e2d6e3fb6a2a"/>
				<textElement verticalAlignment="Middle"/>
				<textFieldExpression><![CDATA[$F{zip}]]></textFieldExpression>
			</textField>
		</band>
	</detail>
</jasperReport>
 类似资料:
  • 问题内容: 是否可以使用XML配置中的规范以编程方式添加Log4J2附加程序? 我计划在log4j2.xml中定义所有内容,然后按情况选择追加器(不会编译): 问题答案: 编辑:有关log4j2的最新版本,请参阅下方答案 我给他们留下了不希望您这样做的印象,但这对我有用:

  • 我找到以下链接来读取JMS队列中的消息及其工作。 https://blogs.oracle.com/soaproactive/entry/jms_step_3_using_the 现在,我想以编程方式读取JMS队列统计信息,如消息数、挂起消息数和消息输入/输出时间等。weblogic或weblogic中是否有可能为此提供任何API? 请帮忙。

  • 问题内容: 我对joptionpane有疑问。 使用JOptionPane.showMessageDialog(…),我们可以创建一个消息对话框。但是如何以编程方式将其关闭? 问题答案: 您总是可以通过获取其持有的任何组件的WindowAncestor来获得对JOptionPane的引用,然后调用或返回Window。该窗口可以通过使用获得 例如:

  • 问题内容: 抱歉,标题…最好用一个例子来描述问题… 我有一个事件列表和每个事件的两个日期,我需要在各自的月份内“中断”或“分发”这些日期。 范例1: 事件 :事件A 开始日期 :12/15/2017-MM / DD / YYYY 结束日期 :2018年1 月 17 日 -MM / DD / YYYY 如果在表上搜索此事件,则会得到包含该数据的结果行。 但是我需要两个结果,如下所示: 结果1:事件A

  • 本文向大家介绍如何在SAP-MDG中存储详细信息?,包括了如何在SAP-MDG中存储详细信息?的使用技巧和注意事项,需要的朋友参考一下 如果您不想创建自定义表,则可以借助重用方法来创建数据模型。然后,您可以将此新创建的数据模型保存在暂存MDG中。您还有其他选择是Z表。您可以创建一个Z表来保留数据。 希望这可以帮助!

  • 我有: 我想要: 似乎在scala中我可以写:< code>df.select($"value。_1 ",$ "值。_2 ",$ "值。_3"),但这在python中是不可能的。 那么有没有好的办法呢?