JasperReport表头的stretchType属性无效的解决

JasperReport 根据内容动态调整报表行高启发:
1.Stretch with overflow 针对TextFileld
2.Stretch Type:relative to tallest object/relative to band height
3.Position type:Float/Fix relative to top/Fix relative to bottom
4.element group(为元素分组)

问题:
表格column多并且表头字数多的时候发现表头不会自动拉伸,打开layout的.jrxml文件,发现表头是使用staticText作为表头文字描述的:(往往表头都是写成静态文本的)
columnHeader节点-->band节点-->

<staticText>
	<reportElement mode="Opaque" backcolor="#CCCCCC" x="2"
		y="0" width="53" height="15" key="staticText-1" stretchType="RelativeToBandHeight">
		<printWhenExpression><![CDATA[$V{PAGE_NUMBER}.intValue() <= 1]]></printWhenExpression>
	</reportElement>
	<box topBorder="Thin" topBorderColor="#000000" leftBorder="Thin"
		leftBorderColor="#000000" rightBorder="Thin" rightBorderColor="#000000"
		bottomBorder="Thin" bottomBorderColor="#000000" />
	<text><![CDATA[This is the Head of Table]]></text>
</staticText>



尽管这里在reportElement节点加入了stretchType="RelativeToBandHeight"属性,但是发现表头并不能自动拉伸。 看过上面文章之后知道,对于staticText的块,这个属性是不起作用的。

解决:

修改为:

<textField isStretchWithOverflow="true">
			<reportElement mode="Opaque" backcolor="#CCCCCC" x="55"
					y="0" width="53" height="15" key="textField-2" stretchType="RelativeToBandHeight"
					positionType="Float">
				<printWhenExpression><![CDATA[$V{PAGE_NUMBER}.intValue() <= 1]]></printWhenExpression>
			</reportElement>
			<box topBorder="Thin" topBorderColor="#000000" leftBorder="None"
					leftBorderColor="#000000" rightBorder="Thin" rightBorderColor="#000000"
					bottomBorder="Thin" bottomBorderColor="#000000" />
			<textElement textAlignment="Center" verticalAlignment="Middle">
				<font fontName="Arial" size="9" isBold="false" pdfFontName="Helvetica"
						isPdfEmbedded="false" pdfEncoding="Cp1252" />
			</textElement>
			<textFieldExpression class="java.lang.String"><![CDATA["This is the Head of Table"]]></textFieldExpression>
</textField>


即可,注意除了把staticText修改为textField 外,
要加入isStretchWithOverflow="true"属性,
另外textFieldExpression 使用双引号修饰原本的static text值。

回头在官网上找一下相关资料印证。另外这个 positionType="Float"属性可能也会起作用,见 http://stackoverflow.com/questions/9377392/how-to-stretch-textfield-in-a-jasperreport-as-per-dynamic-content




评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值