Jasper Studio 重复块
Jasper Studio repeating block
我有一个任务,要创建 JasperReoirts 报告,其中包含动态重复块
像这样:
"You're cool guy because:
Reason:$F{reason}
Description: $F{desc}
Grade: $F{grade}
"
带有 reason\desc\grade 的块可以重复多次,具体取决于 DTO 对象中的 java 集合。我应该使用哪种仪器?我试过列表,但它看起来像单个字段,而不是块。
例如:
我有 jasper 报告的 DTO 对象,其中包含对象列表,列表。列表中的这个对象有 3 个字符串字段(原因、描述、等级)。所以在报告中我想看到它就像列表
中每个元素的重复块
StopListReasons:
Reason: someReason1
Description: someDescription1
Grade: someGrade1
Reason: someReason2
Description: someDescription2
Grade: someGrade2
Reason: someReason3
Description: someDescription3
Grade: someGrade3
我尝试创建 table,该行包含 3 个标签和 3 个文本字段,但在预览时它是空的。我也在寻找 List 元素,但看起来它与我的情况不符。
也许使用 jrxml 中的代码这个问题会变得更清楚
<subDataset name="Dataset1" uuid="c5f7a5d1-6262-4003-a4fb-146ba8515c34">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="adapter.xml"/>
<queryString language="XPath">
<![CDATA[/report/stopListInfos/slInfo]]>
</queryString>
<field name="stopListCode" class="java.lang.String">
<fieldDescription><![CDATA[stopListCode]]></fieldDescription>
</field>
<field name="stopListResult" class="java.lang.String">
<fieldDescription><![CDATA[stopListResult]]></fieldDescription>
</field>
<field name="clientType" class="java.lang.String">
<fieldDescription><![CDATA[clientType]]></fieldDescription>
</field>
</subDataset>
还有 table
<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" whenNoDataType="AllSectionsNoDetail">
<datasetRun subDataset="Dataset1" uuid="a5a0cf80-5aa6-415c-b31c-044bb856c70c">
<dataSourceExpression><![CDATA[((net.sf.jasperreports.engine.data.JRXmlDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("/report/StopListInfos/slInfo")]]></dataSourceExpression>
</datasetRun>
<jr:column width="66" uuid="aa9f5289-56ad-47df-93cf-8a81770ecd4c">
<property name="com.jaspersoft.studio.components.table.model.column.name" value="Column1"/>
<jr:detailCell style="Table_TD" height="110">
<staticText>
<reportElement x="0" y="0" width="66" height="38" uuid="9fa05583-38e1-4cd2-b717-7f953ed29042"/>
<text><![CDATA[1]]></text>
</staticText>
<staticText>
<reportElement x="0" y="38" width="66" height="36" uuid="915e8324-e9b9-452d-983c-3e241f34eb46"/>
<text><![CDATA[2]]></text>
</staticText>
<staticText>
<reportElement x="0" y="74" width="66" height="36" uuid="fc7a9e65-2573-405d-bd3f-c519bd93d162"/>
<text><![CDATA[3]]></text>
</staticText>
</jr:detailCell>
</jr:column>
<jr:column width="134" uuid="82a313a6-2d55-418e-af19-a3ff9439bd6a">
<property name="com.jaspersoft.studio.components.table.model.column.name" value="Column2"/>
<jr:detailCell style="Table_TD" height="110">
<textField>
<reportElement x="0" y="0" width="134" height="38" uuid="003483c6-9aa4-43fe-8d8c-2a5aef9ccc3f"/>
<textFieldExpression><![CDATA[$F{stopListCode}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="38" width="134" height="36" uuid="f3f7f9f6-7482-41a7-a473-0fa5d1a4bbed"/>
<textFieldExpression><![CDATA[$F{stopListResult}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="74" width="134" height="36" uuid="8ca9059f-7c71-44ff-96fd-7b490d4f7c0e"/>
<textFieldExpression><![CDATA[$F{clientType}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
</jr:table>
解决方案是将 table 与 2 列一起使用,此 table 的每一行在第一列中包含 3 个静态 "rows",在我的动态中包含 3 个 "rows"第二列中的值。
在 jrxml 中它将是
<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="Dataset1" uuid="c9a09593-11ee-4817-95f6-bd2903bdf820">
<datasetParameter name="ulInfo">
<datasetParameterExpression><![CDATA["ID Клиента в Мастер-системе – "+$F{clientId}+", ИНН – "+$F{inn} +", Наименование - " + $F{shortName}]]></datasetParameterExpression>
</datasetParameter>
<datasetParameter name="flInfo">
<datasetParameterExpression><![CDATA["ФИО - " + $F{clientFIO} + ", дата рождения - " + $F{clientBirthDate}]]></datasetParameterExpression>
</datasetParameter>
<dataSourceExpression><![CDATA[((net.sf.jasperreports.engine.data.JRXmlDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("/report/stopListInfos/slInfo")]]></dataSourceExpression>
</datasetRun>
<jr:column width="120" uuid="aa9f5289-56ad-47df-93cf-8a81770ecd4c">
<property name="com.jaspersoft.studio.components.table.model.column.name" value="Column1"/>
<jr:detailCell style="Table_TD" height="80">
<staticText>
<reportElement x="0" y="0" width="120" height="20" uuid="9fa05583-38e1-4cd2-b717-7f953ed29042">
<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
</reportElement>
<textElement>
<font fontName="Times New Roman" size="12" isBold="true"/>
</textElement>
<text><![CDATA[Код Стоп-листа:]]></text>
</staticText>
<staticText>
<reportElement x="0" y="20" width="120" height="20" uuid="915e8324-e9b9-452d-983c-3e241f34eb46"/>
<textElement>
<font fontName="Times New Roman" size="12" isBold="true"/>
</textElement>
<text><![CDATA[Тип клиента:]]></text>
</staticText>
<staticText>
<reportElement x="0" y="40" width="120" height="20" uuid="fc7a9e65-2573-405d-bd3f-c519bd93d162">
<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
</reportElement>
<textElement>
<font fontName="Times New Roman" size="12" isBold="true"/>
</textElement>
<text><![CDATA[Реквизиты клиента:]]></text>
</staticText>
<staticText>
<reportElement x="0" y="60" width="120" height="20" uuid="df0465cc-c3ab-4393-a12a-817c1ff749c7">
<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
</reportElement>
<textElement>
<font fontName="Times New Roman" size="12" isBold="true"/>
</textElement>
<text><![CDATA[]]></text>
</staticText>
</jr:detailCell>
</jr:column>
<jr:column width="400" uuid="82a313a6-2d55-418e-af19-a3ff9439bd6a">
<property name="com.jaspersoft.studio.components.table.model.column.name" value="Column2"/>
<jr:detailCell style="Table_TD" height="80">
<textField>
<reportElement x="0" y="0" width="400" height="20" uuid="003483c6-9aa4-43fe-8d8c-2a5aef9ccc3f"/>
<textElement>
<font fontName="Times New Roman" size="12"/>
</textElement>
<textFieldExpression><![CDATA[$F{stopListCode} + " " +$F{stopListResult}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="20" width="400" height="20" uuid="f3f7f9f6-7482-41a7-a473-0fa5d1a4bbed"/>
<textElement>
<font fontName="Times New Roman" size="12"/>
</textElement>
<textFieldExpression><![CDATA[$F{clientType}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="40" width="400" height="20" uuid="8ca9059f-7c71-44ff-96fd-7b490d4f7c0e">
<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
</reportElement>
<textElement>
<font fontName="Times New Roman" size="12"/>
</textElement>
<textFieldExpression><![CDATA[$F{clientType}.equals("ЮЛ") ? $P{ulInfo} : $P{flInfo}]]></textFieldExpression>
</textField>
<staticText>
<reportElement x="0" y="60" width="400" height="20" uuid="19825a9f-d99a-4a98-b143-9fa91edc37a6">
<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
</reportElement>
<textElement>
<font fontName="Times New Roman" size="12" isBold="true"/>
</textElement>
<text><![CDATA[]]></text>
</staticText>
</jr:detailCell>
</jr:column>
</jr:table>
此外,我还遇到了其他问题 - 如何从 table 访问主要报告字段。答案 - 使用 table 数据集中的参数。
我有一个任务,要创建 JasperReoirts 报告,其中包含动态重复块
像这样:
"You're cool guy because:
Reason:$F{reason}
Description: $F{desc}
Grade: $F{grade}
"
带有 reason\desc\grade 的块可以重复多次,具体取决于 DTO 对象中的 java 集合。我应该使用哪种仪器?我试过列表,但它看起来像单个字段,而不是块。
例如: 我有 jasper 报告的 DTO 对象,其中包含对象列表,列表。列表中的这个对象有 3 个字符串字段(原因、描述、等级)。所以在报告中我想看到它就像列表
中每个元素的重复块StopListReasons:
Reason: someReason1
Description: someDescription1
Grade: someGrade1
Reason: someReason2
Description: someDescription2
Grade: someGrade2
Reason: someReason3
Description: someDescription3
Grade: someGrade3
我尝试创建 table,该行包含 3 个标签和 3 个文本字段,但在预览时它是空的。我也在寻找 List 元素,但看起来它与我的情况不符。
也许使用 jrxml 中的代码这个问题会变得更清楚
<subDataset name="Dataset1" uuid="c5f7a5d1-6262-4003-a4fb-146ba8515c34">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="adapter.xml"/>
<queryString language="XPath">
<![CDATA[/report/stopListInfos/slInfo]]>
</queryString>
<field name="stopListCode" class="java.lang.String">
<fieldDescription><![CDATA[stopListCode]]></fieldDescription>
</field>
<field name="stopListResult" class="java.lang.String">
<fieldDescription><![CDATA[stopListResult]]></fieldDescription>
</field>
<field name="clientType" class="java.lang.String">
<fieldDescription><![CDATA[clientType]]></fieldDescription>
</field>
</subDataset>
还有 table
<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" whenNoDataType="AllSectionsNoDetail">
<datasetRun subDataset="Dataset1" uuid="a5a0cf80-5aa6-415c-b31c-044bb856c70c">
<dataSourceExpression><![CDATA[((net.sf.jasperreports.engine.data.JRXmlDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("/report/StopListInfos/slInfo")]]></dataSourceExpression>
</datasetRun>
<jr:column width="66" uuid="aa9f5289-56ad-47df-93cf-8a81770ecd4c">
<property name="com.jaspersoft.studio.components.table.model.column.name" value="Column1"/>
<jr:detailCell style="Table_TD" height="110">
<staticText>
<reportElement x="0" y="0" width="66" height="38" uuid="9fa05583-38e1-4cd2-b717-7f953ed29042"/>
<text><![CDATA[1]]></text>
</staticText>
<staticText>
<reportElement x="0" y="38" width="66" height="36" uuid="915e8324-e9b9-452d-983c-3e241f34eb46"/>
<text><![CDATA[2]]></text>
</staticText>
<staticText>
<reportElement x="0" y="74" width="66" height="36" uuid="fc7a9e65-2573-405d-bd3f-c519bd93d162"/>
<text><![CDATA[3]]></text>
</staticText>
</jr:detailCell>
</jr:column>
<jr:column width="134" uuid="82a313a6-2d55-418e-af19-a3ff9439bd6a">
<property name="com.jaspersoft.studio.components.table.model.column.name" value="Column2"/>
<jr:detailCell style="Table_TD" height="110">
<textField>
<reportElement x="0" y="0" width="134" height="38" uuid="003483c6-9aa4-43fe-8d8c-2a5aef9ccc3f"/>
<textFieldExpression><![CDATA[$F{stopListCode}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="38" width="134" height="36" uuid="f3f7f9f6-7482-41a7-a473-0fa5d1a4bbed"/>
<textFieldExpression><![CDATA[$F{stopListResult}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="74" width="134" height="36" uuid="8ca9059f-7c71-44ff-96fd-7b490d4f7c0e"/>
<textFieldExpression><![CDATA[$F{clientType}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
</jr:table>
解决方案是将 table 与 2 列一起使用,此 table 的每一行在第一列中包含 3 个静态 "rows",在我的动态中包含 3 个 "rows"第二列中的值。 在 jrxml 中它将是
<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="Dataset1" uuid="c9a09593-11ee-4817-95f6-bd2903bdf820">
<datasetParameter name="ulInfo">
<datasetParameterExpression><![CDATA["ID Клиента в Мастер-системе – "+$F{clientId}+", ИНН – "+$F{inn} +", Наименование - " + $F{shortName}]]></datasetParameterExpression>
</datasetParameter>
<datasetParameter name="flInfo">
<datasetParameterExpression><![CDATA["ФИО - " + $F{clientFIO} + ", дата рождения - " + $F{clientBirthDate}]]></datasetParameterExpression>
</datasetParameter>
<dataSourceExpression><![CDATA[((net.sf.jasperreports.engine.data.JRXmlDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("/report/stopListInfos/slInfo")]]></dataSourceExpression>
</datasetRun>
<jr:column width="120" uuid="aa9f5289-56ad-47df-93cf-8a81770ecd4c">
<property name="com.jaspersoft.studio.components.table.model.column.name" value="Column1"/>
<jr:detailCell style="Table_TD" height="80">
<staticText>
<reportElement x="0" y="0" width="120" height="20" uuid="9fa05583-38e1-4cd2-b717-7f953ed29042">
<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
</reportElement>
<textElement>
<font fontName="Times New Roman" size="12" isBold="true"/>
</textElement>
<text><![CDATA[Код Стоп-листа:]]></text>
</staticText>
<staticText>
<reportElement x="0" y="20" width="120" height="20" uuid="915e8324-e9b9-452d-983c-3e241f34eb46"/>
<textElement>
<font fontName="Times New Roman" size="12" isBold="true"/>
</textElement>
<text><![CDATA[Тип клиента:]]></text>
</staticText>
<staticText>
<reportElement x="0" y="40" width="120" height="20" uuid="fc7a9e65-2573-405d-bd3f-c519bd93d162">
<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
</reportElement>
<textElement>
<font fontName="Times New Roman" size="12" isBold="true"/>
</textElement>
<text><![CDATA[Реквизиты клиента:]]></text>
</staticText>
<staticText>
<reportElement x="0" y="60" width="120" height="20" uuid="df0465cc-c3ab-4393-a12a-817c1ff749c7">
<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
</reportElement>
<textElement>
<font fontName="Times New Roman" size="12" isBold="true"/>
</textElement>
<text><![CDATA[]]></text>
</staticText>
</jr:detailCell>
</jr:column>
<jr:column width="400" uuid="82a313a6-2d55-418e-af19-a3ff9439bd6a">
<property name="com.jaspersoft.studio.components.table.model.column.name" value="Column2"/>
<jr:detailCell style="Table_TD" height="80">
<textField>
<reportElement x="0" y="0" width="400" height="20" uuid="003483c6-9aa4-43fe-8d8c-2a5aef9ccc3f"/>
<textElement>
<font fontName="Times New Roman" size="12"/>
</textElement>
<textFieldExpression><![CDATA[$F{stopListCode} + " " +$F{stopListResult}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="20" width="400" height="20" uuid="f3f7f9f6-7482-41a7-a473-0fa5d1a4bbed"/>
<textElement>
<font fontName="Times New Roman" size="12"/>
</textElement>
<textFieldExpression><![CDATA[$F{clientType}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="40" width="400" height="20" uuid="8ca9059f-7c71-44ff-96fd-7b490d4f7c0e">
<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
</reportElement>
<textElement>
<font fontName="Times New Roman" size="12"/>
</textElement>
<textFieldExpression><![CDATA[$F{clientType}.equals("ЮЛ") ? $P{ulInfo} : $P{flInfo}]]></textFieldExpression>
</textField>
<staticText>
<reportElement x="0" y="60" width="400" height="20" uuid="19825a9f-d99a-4a98-b143-9fa91edc37a6">
<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
</reportElement>
<textElement>
<font fontName="Times New Roman" size="12" isBold="true"/>
</textElement>
<text><![CDATA[]]></text>
</staticText>
</jr:detailCell>
</jr:column>
</jr:table>
此外,我还遇到了其他问题 - 如何从 table 访问主要报告字段。答案 - 使用 table 数据集中的参数。