【发布时间】:2019-02-18 18:45:52
【问题描述】:
我正在使用 Jaspersoft iReport 设计器 4.7.0。我想创建一个包含 3 列的表格,表格中的每个单元格都需要拉伸到数据源的最大对象。
我尝试过更改文本元素 Position-float;stretch with overflow - true,Stretch type - 相对于最高对象的属性,但它仅适用于一行。
我希望这对表格的所有行都有效。
当前输出
预期输出
**使用的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="report3" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="f32dfce1-c0d4-4f20-b896-653e7497d7ba">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<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>
<subDataset name="tabeDataSet" uuid="46e73a3d-e883-4c74-a062-6984cc6dac58">
<field name="id" class="java.lang.String"/>
<field name="city" class="java.lang.String"/>
<field name="street" class="java.lang.String"/>
</subDataset>
<subDataset name="Table Dataset 1" uuid="4a76bbab-d785-49f2-82aa-705ea0a2e0d1"/>
<subDataset name="Table Dataset 2" uuid="984926ca-9b74-4713-a4a8-25e7e3a32697"/>
<parameter name="tableData" class="net.sf.jasperreports.engine.data.JRBeanCollectionDataSource"/>
<detail>
<band height="191">
<componentElement>
<reportElement uuid="6e73c624-495f-4558-bfe4-65a0487825ab" key="table 1" x="74" y="49" width="360" height="52"/>
<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="tabeDataSet" uuid="dcaeff11-66ee-47b5-af06-d2f183cb5830">
<dataSourceExpression><![CDATA[$P{tableData}]]></dataSourceExpression>
</datasetRun>
<jr:column uuid="ad308669-ebfb-43ca-b518-326779bbb20e" width="90">
<jr:detailCell height="20">
<textField isStretchWithOverflow="true">
<reportElement uuid="34fe3944-c103-4c85-b509-22df1b589d11" positionType="Float" stretchType="RelativeToTallestObject" x="0" y="0" width="90" height="20"/>
<box>
<pen lineWidth="0.5"/>
<topPen lineWidth="0.5"/>
<leftPen lineWidth="0.5"/>
<bottomPen lineWidth="0.5"/>
<rightPen lineWidth="0.5"/>
</box>
<textElement/>
<textFieldExpression><![CDATA[$F{id}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column uuid="0dbf249d-ee6e-4431-bba2-6d13b610582f" width="90">
<jr:detailCell height="20">
<textField isStretchWithOverflow="true">
<reportElement uuid="886ba9a8-98bc-43cf-9abd-c6fd0410029a" positionType="Float" stretchType="RelativeToTallestObject" x="0" y="0" width="90" height="20"/>
<box>
<pen lineWidth="0.5"/>
<topPen lineWidth="0.5"/>
<leftPen lineWidth="0.5"/>
<bottomPen lineWidth="0.5"/>
<rightPen lineWidth="0.5"/>
</box>
<textElement/>
<textFieldExpression><![CDATA[$F{city}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column uuid="edbd158e-278a-4a5d-98ab-4ea592001ee9" width="90">
<jr:detailCell height="20">
<textField isStretchWithOverflow="true">
<reportElement uuid="59ec1fc2-0a76-4c4c-96b0-7e2b5fbad3df" positionType="Float" stretchType="RelativeToTallestObject" x="0" y="0" width="90" height="20"/>
<box>
<pen lineWidth="0.5"/>
<topPen lineWidth="0.5"/>
<leftPen lineWidth="0.5"/>
<bottomPen lineWidth="0.5"/>
<rightPen lineWidth="0.5"/>
</box>
<textElement/>
<textFieldExpression><![CDATA[$F{street}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
</jr:table>
</componentElement>
</band>
</detail>
</jasperReport>
【问题讨论】:
-
请与数据分享报告预览
-
@Rathnayake 我已附上当前和预期的报告输出格式。请查看并建议
-
@Rathnayake 这可以实现吗?请帮忙!
-
抱歉迟到了。
isStretchWithOverflow="true"根据数据长度动态设置行高。所以你的格式不可能以默认方式。我对此一无所知。请参考 Petter 的回答
标签: java jasper-reports