我正在生成一个包含跨不同页面的联系人的报告。
以前,我将isSplitAllowed设置为“ true”。
但我不希望联系人分散在不同页面上。
因此,将其设置为“ false”,报表的布局看起来要好得多。但是,它引入了一个新问题:
在标题中,我打印页面的第一个人和最后一位的名称。
当联系人被推送到下一页时,仍在当前页面中进行处理。
假设Bob应该位于第一页的底部。但是为了防止拆分,鲍勃现在是第二页中的第一个元素。
但是在我的第一页的标题上,我仍然有Alice ... Bob(其中Alice是第一页的第一人)。
在第二页上,我仍然有Brenda ... Doug(Brenda现在是第二页的第二个人,而Doug是第二页的最后一位)。
我在标题处的输出是
[$ V {pageFirstItem} +“ ...” + $ V {pageLastItem}]]>
其中pageFirstItem是:
<variable name="pageFirstItem" class="java.lang.String" resetType="Page" calculation="First">
<variableExpression><![CDATA[$F{lastName}]]></variableExpression>
<initialValueExpression><![CDATA[$F{lastName}]]></initialValueExpression>
</variable>
和pageLastItem是:
<variable name="pageLastItem" class="java.lang.String" resetType="Report" calculation="Nothing">
<variableExpression><![CDATA[$F{lastName}]]></variableExpression>
最佳答案
我在下面附加了基于iReport 3.0.5的工作示例解决方法。您可以通过启用和禁用isSplitAllowed
对其进行测试。问题是即使isSplitAllowed="false"
强制将记录打印在页面i + 1上,也会在页面i上处理详细记录。
摘要:
对于firstItem
,不需要计算。只需将“名称”字段放在标题中即可。
对于lastItem
,您需要保存使用类型为prop
的变量java.util.Property
处理的名称。这是通过在详细信息部分中将高度为0的虚拟文本字段设置为以下值prop.setProperty("lastSavedName", $F{Name})
来完成的。此textField确保仅在打印名称后才保存名称。
然后将属性prop.getProperty("lastSavedName")
中的值放在带有evaluationTime="Page"
的标题中。
<?xml version="1.0" encoding="UTF-8" ?>
<!-- Created with iReport - A designer for JasperReports -->
<!DOCTYPE jasperReport PUBLIC "//JasperReports//DTD Report Design//EN" "http://jasperreports.sourceforge.net/dtds/jasperreport.dtd">
<jasperReport
name="Untitled_report_1"
columnCount="1"
printOrder="Vertical"
orientation="Portrait"
pageWidth="595"
pageHeight="842"
columnWidth="535"
columnSpacing="0"
leftMargin="30"
rightMargin="30"
topMargin="20"
bottomMargin="20"
whenNoDataType="NoPages"
isFloatColumnFooter="true"
isTitleNewPage="false"
isSummaryNewPage="true">
<property name="ireport.zoom" value="1.0" />
<property name="ireport.x" value="0" />
<property name="ireport.y" value="0" />
<property name="ireport.scriptlethandling" value="0" />
<property name="ireport.encoding" value="UTF-8" />
<import value="java.util.*" />
<import value="net.sf.jasperreports.engine.*" />
<import value="net.sf.jasperreports.engine.data.*" />
<queryString><![CDATA[select 1 as id, 'Name 1' as name from dual union all
select 2 as id, 'Name 2' as name from dual union all
select 3 as id, 'Name 3' as name from dual union all
select 4 as id, 'Name 4' as name from dual union all
select 5 as id, 'Name 5' as name from dual union all
select 6 as id, 'Name 6' as name from dual union all
select 7 as id, 'Name 7' as name from dual union all
select 8 as id, 'Name 8' as name from dual union all
select 9 as id, 'Name 9' as name from dual union all
select 10 as id, 'Name 10' as name from dual union all
select 11 as id, 'Name 11' as name from dual union all
select 12 as id, 'Name 12' as name from dual union all
select 13 as id, 'Name 13' as name from dual union all
select 14 as id, 'Name 14' as name from dual union all
select 15 as id, 'Name 15' as name from dual union all
select 16 as id, 'Name 16' as name from dual union all
select 17 as id, 'Name 17' as name from dual union all
select 18 as id, 'Name 18' as name from dual union all
select 19 as id, 'Name 19' as name from dual union all
select 20 as id, 'Name 20' as name from dual union all
select 21 as id, 'Name 21' as name from dual union all
select 22 as id, 'Name 22' as name from dual union all
select 23 as id, 'Name 23' as name from dual union all
select 24 as id, 'Name 24' as name from dual union all
select 25 as id, 'Name 25' as name from dual union all
select 26 as id, 'Name 26' as name from dual union all
select 27 as id, 'Name 27' as name from dual union all
select 28 as id, 'Name 28' as name from dual]]></queryString>
<field name="ID" class="java.math.BigDecimal"/>
<field name="NAME" class="java.lang.String"/>
<variable name="prop" class="java.util.Properties" resetType="Report" calculation="System">
<initialValueExpression><![CDATA[new Properties()]]></initialValueExpression>
</variable>
<background>
<band height="0" isSplitAllowed="true" >
</band>
</background>
<title>
<band height="0" isSplitAllowed="true" >
</band>
</title>
<pageHeader>
<band height="16" isSplitAllowed="true" >
<textField isStretchWithOverflow="false" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" >
<reportElement
x="0"
y="0"
width="96"
height="16"
key="textField-3"/>
<box></box>
<textElement>
<font/>
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA["First " + $F{ID}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="false" isBlankWhenNull="false" evaluationTime="Page" hyperlinkType="None" hyperlinkTarget="Self" >
<reportElement
x="96"
y="0"
width="100"
height="16"
key="textField-4"/>
<box></box>
<textElement>
<font/>
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA["Last " + $V{prop}.getProperty("abcd")]]></textFieldExpression>
</textField>
</band>
</pageHeader>
<columnHeader>
<band height="20" isSplitAllowed="true" >
<staticText>
<reportElement
x="0"
y="0"
width="96"
height="20"
key="staticText-2"/>
<box></box>
<textElement>
<font/>
</textElement>
<text><![CDATA[CustomerName]]></text>
</staticText>
<staticText>
<reportElement
x="96"
y="0"
width="100"
height="20"
key="staticText-3"/>
<box></box>
<textElement>
<font/>
</textElement>
<text><![CDATA[Workorderid]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="18" isSplitAllowed="true" >
<textField isStretchWithOverflow="true" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" >
<reportElement
x="0"
y="0"
width="96"
height="18"
key="textField"/>
<box></box>
<textElement>
<font/>
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[$F{NAME}+"This\nwill\ncause\na\nsplit."]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="false" pattern="##0.00" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" >
<reportElement
x="96"
y="0"
width="100"
height="18"
key="textField"/>
<box></box>
<textElement>
<font/>
</textElement>
<textFieldExpression class="java.math.BigDecimal"><![CDATA[$F{ID}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="false" isBlankWhenNull="false" evaluationTime="Band" hyperlinkType="None" hyperlinkTarget="Self" >
<reportElement
x="196"
y="0"
width="339"
height="0"
key="textField-5"
isRemoveLineWhenBlank="true"/>
<box></box>
<textElement>
<font/>
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[$V{prop}.setProperty("abcd", String.valueOf($F{ID}))]]></textFieldExpression>
</textField>
</band>
</detail>
<columnFooter>
<band height="0" isSplitAllowed="true" >
</band>
</columnFooter>
<pageFooter>
<band height="0" isSplitAllowed="true" >
</band>
</pageFooter>
<summary>
<band height="0" isSplitAllowed="true" >
</band>
</summary>
</jasperReport>