ireport table中元素内容超出纸张剩余空间,导致出现空白页问题的解决方法

  1. 问题:我们在使用table组件输出多条记录,发现如果某条记录的内容过多时,生成的报告中间几页,剩余部分区域会出现空白的问题,空白不均匀,有的页显示一小部分内容,剩下大部分空间都是空白,有的显示一大部分内容,剩下一小部分空间显示空白,如图所示:

  2. 原因:去官方社区查询问题,发现ireport本身机制就是这样,当下一元素内容超出当前页剩余空间,则重新创建一个新的页面去渲染内容,而当前页剩余的空间不管多少都留白
  3. 解决:在这里吐槽一下,这很不合理,官方的意思是不这样做,会出现内容渲染错乱问题,好吧,那既然这样就、是不是就没办法了,当然不是,办法总比困难多嘛,经过各种尝试,发现ireport里面有一个List控件也可以循环打印数据,和table类似
  4. 从组件面板拖拽一个list控件到展示区域
     

  5. 创建一个样式,并设置Padding and borders属性,为list控件设置边框

  6. 选中list控件,设置Style属性,选中新增的style样式

  7. 和table控件一样,设置好数据源,拖入要展示的textfield组件,并设置上边框

  8. 设置textfiled属性

  9. 在textfield控件之间加上line组件,作为分割线,这里不用textfield控件的边框作为分割线,是因为会出现分割线和list控件边框断开的问题,具体原因应该是和list控件本不是table控件有关,所以无法做到多个列的大小同步扩充,导致连线断开问题

  10. 设置line控件属性

  11. 最后看下输出结果,完美解决问题

  12. 模板代码:复制后保存到文本中,后缀改成jrxml就可以用ireport工具打开
     
    <?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="property_report" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="30" uuid="d8114e8f-e215-48b2-b499-d089ee151842">
    	<property name="ireport.zoom" value="1.2100000000000075"/>
    	<property name="ireport.x" value="0"/>
    	<property name="ireport.y" value="0"/>
    	<style name="style1"/>
    	<style name="table">
    		<box>
    			<pen lineWidth="1.0" lineColor="#000000"/>
    		</box>
    	</style>
    	<style name="table_TH" mode="Opaque" backcolor="#F0F8FF">
    		<box>
    			<pen lineWidth="0.5" lineColor="#000000"/>
    		</box>
    	</style>
    	<style name="table_CH" mode="Opaque" backcolor="#BFE1FF">
    		<box>
    			<pen lineWidth="0.5" lineColor="#000000"/>
    		</box>
    	</style>
    	<style name="table_TD" mode="Opaque" backcolor="#FFFFFF">
    		<box>
    			<pen lineWidth="0.5" lineColor="#000000"/>
    		</box>
    	</style>
    	<style name="style_update" style="table_TD" mode="Opaque" backcolor="#FF0000" pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H"/>
    	<style name="table 3_TH" mode="Opaque" backcolor="#F0F8FF">
    		<box>
    			<topPen lineWidth="0.5" lineColor="#000000"/>
    			<bottomPen lineWidth="0.5" lineColor="#000000"/>
    		</box>
    	</style>
    	<style name="table 4_CH" mode="Opaque" backcolor="#FFF3E6">
    		<box>
    			<topPen lineWidth="0.5" lineColor="#CCCCCC"/>
    			<bottomPen lineWidth="0.5" lineColor="#CCCCCC"/>
    		</box>
    	</style>
    	<style name="table 3_TD" mode="Opaque" backcolor="#FFFFFF">
    		<box>
    			<topPen lineWidth="0.5" lineColor="#000000"/>
    			<bottomPen lineWidth="0.5" lineColor="#000000"/>
    		</box>
    	</style>
    	<style name="table_1">
    		<box>
    			<pen lineWidth="1.0" lineColor="#000000"/>
    		</box>
    	</style>
    	<style name="table 3_CH" mode="Opaque" backcolor="#BFE1FF">
    		<box>
    			<topPen lineWidth="0.5" lineColor="#000000"/>
    			<bottomPen lineWidth="0.5" lineColor="#000000"/>
    		</box>
    	</style>
    	<style name="table 5">
    		<box>
    			<pen lineWidth="1.0" lineColor="#000000"/>
    		</box>
    	</style>
    	<style name="table 3">
    		<box>
    			<pen lineWidth="1.0" lineColor="#000000"/>
    		</box>
    	</style>
    	<style name="table 1_CH" mode="Opaque" backcolor="#BFE1FF">
    		<box>
    			<pen lineWidth="0.5" lineColor="#000000"/>
    		</box>
    	</style>
    	<style name="table 2">
    		<box>
    			<pen lineWidth="1.0" lineColor="#000000"/>
    		</box>
    	</style>
    	<style name="table 5_TD" mode="Opaque" backcolor="#FFFFFF">
    		<box>
    			<pen lineWidth="0.5" lineColor="#000000"/>
    		</box>
    		<conditionalStyle>
    			<style/>
    		</conditionalStyle>
    	</style>
    	<style name="table 4_TD" mode="Opaque" backcolor="#FFFFFF">
    		<box>
    			<topPen lineWidth="0.5" lineColor="#CCCCCC"/>
    			<bottomPen lineWidth="0.5" lineColor="#CCCCCC"/>
    		</box>
    		<conditionalStyle>
    			<conditionExpression><![CDATA[new Boolean($V{REPORT_COUNT}.intValue()%2==0)]]></conditionExpression>
    			<style backcolor="#FFFCF8"/>
    		</conditionalStyle>
    	</style>
    	<style name="table 5_CH" mode="Opaque" backcolor="#BFE1FF">
    		<box>
    			<pen lineWidth="0.5" lineColor="#000000"/>
    		</box>
    	</style>
    	<style name="table 4_TH" mode="Opaque" backcolor="#D9CFC3">
    		<box>
    			<topPen lineWidth="0.5" lineColor="#CCCCCC"/>
    			<bottomPen lineWidth="0.5" lineColor="#CCCCCC"/>
    		</box>
    	</style>
    	<style name="table 2_TH" mode="Opaque" backcolor="#F0F8FF">
    		<box>
    			<pen lineWidth="0.5" lineColor="#000000"/>
    		</box>
    	</style>
    	<style name="table_CH_1" mode="Opaque" backcolor="#BFE1FF">
    		<box>
    			<pen lineWidth="0.5" lineColor="#000000"/>
    		</box>
    	</style>
    	<style name="table 1">
    		<box>
    			<pen lineWidth="1.0" lineColor="#000000"/>
    		</box>
    	</style>
    	<style name="table 5_TH" mode="Opaque" backcolor="#F0F8FF">
    		<box>
    			<pen lineWidth="0.5" lineColor="#000000"/>
    		</box>
    	</style>
    	<style name="table_TH_1" mode="Opaque" backcolor="#F0F8FF">
    		<box>
    			<pen lineWidth="0.5" lineColor="#000000"/>
    		</box>
    	</style>
    	<style name="table_TD_1" mode="Opaque" backcolor="#FFFFFF">
    		<box>
    			<pen lineWidth="0.5" lineColor="#000000"/>
    		</box>
    	</style>
    	<style name="table 1_TD" mode="Opaque" backcolor="#FFFFFF">
    		<box>
    			<pen lineWidth="0.5" lineColor="#000000"/>
    		</box>
    	</style>
    	<style name="table 2_CH" mode="Opaque" backcolor="#BFE1FF">
    		<box>
    			<pen lineWidth="0.5" lineColor="#000000"/>
    		</box>
    	</style>
    	<style name="table 1_TH" mode="Opaque" backcolor="#F0F8FF">
    		<box>
    			<pen lineWidth="0.5" lineColor="#000000"/>
    		</box>
    	</style>
    	<style name="table 4">
    		<box>
    			<topPen lineWidth="1.0" lineColor="#CCCCCC"/>
    			<bottomPen lineWidth="1.0" lineColor="#CCCCCC"/>
    		</box>
    	</style>
    	<style name="table 2_TD" mode="Opaque" backcolor="#FFFFFF">
    		<box>
    			<pen lineWidth="0.5" lineColor="#000000"/>
    		</box>
    	</style>
    	<style name="listStyle" mode="Transparent">
    		<pen lineWidth="0.5"/>
    		<box>
    			<topPen lineWidth="1.0"/>
    			<leftPen lineWidth="1.0"/>
    			<bottomPen lineWidth="1.0"/>
    			<rightPen lineWidth="1.0"/>
    		</box>
    	</style>
    	<subDataset name="trustElements" uuid="65895edd-ea94-4336-8985-ee883521bfdb">
    		<queryString>
    			<![CDATA[]]>
    		</queryString>
    		<field name="class" class="java.lang.Class">
    			<fieldDescription><![CDATA[class]]></fieldDescription>
    		</field>
    		<field name="col1" class="java.lang.String">
    			<fieldDescription><![CDATA[col1]]></fieldDescription>
    		</field>
    		<field name="col2" class="java.lang.String">
    			<fieldDescription><![CDATA[col2]]></fieldDescription>
    		</field>
    		<field name="col3" class="java.lang.String">
    			<fieldDescription><![CDATA[col3]]></fieldDescription>
    		</field>
    		<field name="col4" class="java.lang.String">
    			<fieldDescription><![CDATA[col4]]></fieldDescription>
    		</field>
    		<field name="name" class="java.lang.String">
    			<fieldDescription><![CDATA[name]]></fieldDescription>
    		</field>
    		<field name="value" class="java.lang.String">
    			<fieldDescription><![CDATA[value]]></fieldDescription>
    		</field>
    	</subDataset>
    	<subDataset name="Table Dataset 1" uuid="7445c0f2-cfec-49aa-bcd4-274bfd1497e3"/>
    	<subDataset name="dataset1" uuid="96638516-1710-4f94-83cb-e8697fdbd246"/>
    	<subDataset name="dataset2" uuid="3a2f554a-5317-4ada-9cbd-e16b55bb7d8c"/>
    	<parameter name="trustInfoDetail" class="net.sf.jasperreports.engine.data.JRBeanCollectionDataSource"/>
    	<parameter name="hgysDetail" class="net.sf.jasperreports.engine.data.JRBeanCollectionDataSource"/>
    	<parameter name="departmentName" class="java.lang.String"/>
    	<parameter name="systime" class="java.lang.String"/>
    	<parameter name="trustInfo" class="java.lang.String"/>
    	<parameter name="title" class="java.lang.String"/>
    	<parameter name="pageImageUrl" class="java.lang.String"/>
    	<background>
    		<band splitType="Stretch"/>
    	</background>
    	<pageHeader>
    		<band height="50">
    			<image hAlign="Right" isLazy="true">
    				<reportElement x="454" y="8" width="100" height="38" uuid="ab55ee65-feb0-4f34-bba3-2ad573bfbcc4"/>
    				<imageExpression><![CDATA[$P{pageImageUrl}]]></imageExpression>
    			</image>
    			<line direction="BottomUp">
    				<reportElement positionType="Float" x="0" y="46" width="555" height="1" uuid="6588f555-7040-4fa3-8476-14669a62c02a"/>
    				<graphicElement>
    					<pen lineWidth="1.0" lineStyle="Solid" lineColor="#666666"/>
    				</graphicElement>
    			</line>
    			<textField isStretchWithOverflow="true">
    				<reportElement positionType="Float" x="1" y="21" width="432" height="23" isPrintWhenDetailOverflows="true" uuid="e7b8888f-3dd0-4477-95d4-617e7cd21474"/>
    				<textElement textAlignment="Left" verticalAlignment="Middle">
    					<font fontName="仿宋_GB2312" size="10" isBold="false" pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H" isPdfEmbedded="true"/>
    				</textElement>
    				<textFieldExpression><![CDATA[$P{title}]]></textFieldExpression>
    			</textField>
    		</band>
    	</pageHeader>
    	<detail>
    		<band height="208">
    			<staticText>
    				<reportElement style="table_TH" positionType="Float" mode="Opaque" x="0" y="104" width="555" height="20" isRemoveLineWhenBlank="true" forecolor="#CCCCCC" backcolor="#B00B2D" uuid="7fd45d55-4af1-42ba-8fd8-70a1d122386b">
    					<printWhenExpression><![CDATA[$P{trustInfoDetail}.getRecordCount()>0]]></printWhenExpression>
    				</reportElement>
    				<box>
    					<pen lineWidth="0.5"/>
    					<topPen lineWidth="0.5" lineColor="#CCCCCC"/>
    					<leftPen lineWidth="0.5"/>
    					<bottomPen lineWidth="0.5"/>
    					<rightPen lineWidth="0.5"/>
    				</box>
    				<textElement textAlignment="Center" verticalAlignment="Middle">
    					<font fontName="仿宋_GB2312" size="12" isBold="true" pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H"/>
    				</textElement>
    				<text><![CDATA[信托要素]]></text>
    			</staticText>
    			<textField isStretchWithOverflow="true">
    				<reportElement x="55" y="32" width="446" height="16" uuid="96fe5c1e-a3a9-488b-a28c-a31b1a1303ab"/>
    				<textElement>
    					<font fontName="仿宋_GB2312" size="11" pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H"/>
    					<paragraph tabStopWidth="23"/>
    				</textElement>
    				<textFieldExpression><![CDATA[$P{trustInfo}]]></textFieldExpression>
    			</textField>
    			<staticText>
    				<reportElement positionType="Float" x="0" y="54" width="110" height="20" uuid="07b8dc02-8e05-4620-95bb-bc31ad53a333"/>
    				<textElement>
    					<font fontName="仿宋_GB2312" size="14" isBold="true" pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H"/>
    				</textElement>
    				<text><![CDATA[二、项目要素]]></text>
    			</staticText>
    			<staticText>
    				<reportElement style="table_TH" positionType="Float" mode="Opaque" x="0" y="149" width="555" height="20" isRemoveLineWhenBlank="true" forecolor="#CCCCCC" backcolor="#B00B2D" uuid="8b9557af-b7a5-4dcd-bb90-bae50aba17f5">
    					<printWhenExpression><![CDATA[$P{hgysDetail}.getRecordCount()>0]]></printWhenExpression>
    				</reportElement>
    				<box>
    					<pen lineWidth="0.5"/>
    					<topPen lineWidth="0.5"/>
    					<leftPen lineWidth="0.5"/>
    					<bottomPen lineWidth="0.5"/>
    					<rightPen lineWidth="0.5"/>
    				</box>
    				<textElement textAlignment="Center" verticalAlignment="Middle">
    					<font fontName="仿宋_GB2312" size="12" isBold="true" pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H"/>
    				</textElement>
    				<text><![CDATA[合规性分析]]></text>
    			</staticText>
    			<staticText>
    				<reportElement positionType="Float" mode="Opaque" x="0" y="81" width="114" height="23" forecolor="#CCCCCC" backcolor="#B00B2D" uuid="4873f27e-fc6b-4cf1-ac5e-e6cf20e58428"/>
    				<box>
    					<pen lineWidth="0.1"/>
    					<topPen lineWidth="0.5" lineColor="#000000"/>
    					<leftPen lineWidth="0.5" lineColor="#000000"/>
    					<bottomPen lineWidth="0.5"/>
    					<rightPen lineWidth="0.5"/>
    				</box>
    				<textElement textAlignment="Center" verticalAlignment="Middle">
    					<font fontName="仿宋_GB2312" size="14" isBold="true" pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H"/>
    				</textElement>
    				<text><![CDATA[要素]]></text>
    			</staticText>
    			<staticText>
    				<reportElement positionType="Float" x="0" y="5" width="110" height="20" uuid="9c493543-b554-448f-b3e5-b9ca6391c5c6"/>
    				<textElement>
    					<font fontName="仿宋_GB2312" size="14" isBold="true" pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H" isPdfEmbedded="true"/>
    				</textElement>
    				<text><![CDATA[一、信托概述]]></text>
    			</staticText>
    			<staticText>
    				<reportElement positionType="Float" mode="Opaque" x="114" y="81" width="441" height="23" forecolor="#CCCCCC" backcolor="#B00B2D" uuid="7d5f36ed-bdbe-4a14-b286-35de88ffe669"/>
    				<box>
    					<pen lineWidth="0.1"/>
    					<topPen lineWidth="0.5" lineColor="#000000"/>
    					<leftPen lineWidth="0.5"/>
    					<bottomPen lineWidth="0.5"/>
    					<rightPen lineWidth="0.5" lineColor="#000000"/>
    				</box>
    				<textElement textAlignment="Center" verticalAlignment="Middle">
    					<font fontName="仿宋_GB2312" size="14" isBold="true" pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H"/>
    				</textElement>
    				<text><![CDATA[内容]]></text>
    			</staticText>
    			<elementGroup>
    				<elementGroup>
    					<elementGroup/>
    				</elementGroup>
    			</elementGroup>
    			<elementGroup/>
    			<componentElement>
    				<reportElement style="listStyle" positionType="Float" mode="Opaque" x="0" y="124" width="554" height="25" uuid="1d0c2e35-3c81-462d-a6f9-7f7a6059be4f"/>
    				<jr:list xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" printOrder="Vertical">
    					<datasetRun subDataset="trustElements" uuid="fbe161be-3441-463f-bdbc-e3ac5a478242">
    						<dataSourceExpression><![CDATA[$P{trustInfoDetail}]]></dataSourceExpression>
    					</datasetRun>
    					<jr:listContents height="25" width="554">
    						<textField isStretchWithOverflow="true" isBlankWhenNull="false">
    							<reportElement positionType="Float" stretchType="RelativeToBandHeight" x="1" y="0" width="113" height="25" uuid="93ac58e1-8fc6-43ed-add5-7186924f75eb"/>
    							<box topPadding="5" leftPadding="5" bottomPadding="5" rightPadding="5">
    								<topPen lineWidth="0.5"/>
    								<rightPen lineWidth="0.0"/>
    							</box>
    							<textElement>
    								<font fontName="仿宋_GB2312" size="11" pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H"/>
    							</textElement>
    							<textFieldExpression><![CDATA[$F{name}]]></textFieldExpression>
    						</textField>
    						<textField isStretchWithOverflow="true" isBlankWhenNull="false">
    							<reportElement positionType="Float" stretchType="RelativeToBandHeight" x="114" y="0" width="440" height="25" uuid="5edbab84-b814-41e4-a65b-4f1162b6fc4f"/>
    							<box topPadding="5" leftPadding="5" bottomPadding="5" rightPadding="5">
    								<topPen lineWidth="0.5"/>
    								<leftPen lineWidth="0.0"/>
    							</box>
    							<textElement>
    								<font fontName="仿宋_GB2312" size="11" isUnderline="false" isStrikeThrough="false" pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H"/>
    								<paragraph lineSpacing="1_1_2"/>
    							</textElement>
    							<textFieldExpression><![CDATA[$F{value}]]></textFieldExpression>
    						</textField>
    						<line>
    							<reportElement positionType="Float" stretchType="RelativeToBandHeight" x="114" y="0" width="1" height="25" isPrintWhenDetailOverflows="true" uuid="24d97671-8418-41fb-9f82-99b6e95306a8"/>
    							<graphicElement>
    								<pen lineWidth="0.5"/>
    							</graphicElement>
    						</line>
    					</jr:listContents>
    				</jr:list>
    			</componentElement>
    			<componentElement>
    				<reportElement style="listStyle" positionType="Float" x="0" y="169" width="554" height="25" uuid="b6f62b9b-bc88-4c92-834f-ef443013af69"/>
    				<jr:list xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" printOrder="Vertical">
    					<datasetRun subDataset="trustElements" uuid="cfa359d4-6c91-40f2-98fc-43f953dfc7e6">
    						<dataSourceExpression><![CDATA[$P{hgysDetail}]]></dataSourceExpression>
    					</datasetRun>
    					<jr:listContents height="25" width="554">
    						<textField isStretchWithOverflow="true">
    							<reportElement positionType="Float" stretchType="RelativeToBandHeight" x="1" y="0" width="113" height="25" uuid="7754f1c8-01ae-4e0e-a6b0-f4b987672c96"/>
    							<box topPadding="5" leftPadding="5" bottomPadding="5" rightPadding="5">
    								<topPen lineWidth="0.5"/>
    								<rightPen lineWidth="0.0"/>
    							</box>
    							<textElement>
    								<font fontName="仿宋_GB2312" size="11" pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H"/>
    							</textElement>
    							<textFieldExpression><![CDATA[$F{name}]]></textFieldExpression>
    						</textField>
    						<textField isStretchWithOverflow="true">
    							<reportElement positionType="Float" stretchType="RelativeToBandHeight" x="115" y="0" width="439" height="25" uuid="e0eba7b0-f164-4e65-8449-3a53eb1ec1cd"/>
    							<box topPadding="5" leftPadding="5" bottomPadding="5" rightPadding="5">
    								<topPen lineWidth="0.5"/>
    								<leftPen lineWidth="0.0"/>
    							</box>
    							<textElement>
    								<font fontName="仿宋_GB2312" size="11" pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H"/>
    								<paragraph lineSpacing="1_1_2"/>
    							</textElement>
    							<textFieldExpression><![CDATA[$F{value}]]></textFieldExpression>
    						</textField>
    						<line>
    							<reportElement positionType="Float" stretchType="RelativeToBandHeight" x="114" y="0" width="1" height="25" isPrintWhenDetailOverflows="true" uuid="fb2db010-45b8-4aca-9a5b-09e94d67f917"/>
    							<graphicElement>
    								<pen lineWidth="0.5"/>
    							</graphicElement>
    						</line>
    					</jr:listContents>
    				</jr:list>
    			</componentElement>
    		</band>
    	</detail>
    </jasperReport>
    

     

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值