目前的需求是要在同一个pdf文件里面打印两张表格,使用json数据源并且是不同的数据源。效果图如下↓

Jasper+ireport实现子报表使用json数据源

这里两张表都是json数据源,主报表采用的是动态数据源,子报表时读取文件里面的数据源。

主报表xml文件如下↓

  1 <?xml version="1.0" encoding="UTF-8"?>
  2 <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="JsonData" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="204d2c12-6e17-4f5a-88d5-797be11591a1">
  3     <property name="ireport.zoom" value="1.0"/>
  4     <property name="ireport.x" value="0"/>
  5     <property name="ireport.y" value="0"/>
  6     <parameter name="SUBREPORT_DIR" class="java.lang.String" isForPrompting="false">
  7         <defaultValueExpression><![CDATA["F:\\reportTest\\"]]></defaultValueExpression>
  8     </parameter>
  9     <queryString language="json">
 10         <![CDATA[sales.item]]>
 11     </queryString>
 12     <field name="equipment" class="java.lang.String"/>
 13     <field name="project" class="java.lang.String"/>
 14     <field name="count" class="java.lang.String"/>
 15     <title>
 16         <band height="79" splitType="Stretch">
 17             <staticText>
 18                 <reportElement x="137" y="0" width="200" height="20" uuid="dfc1b3b3-97f7-4168-8509-1b611bea72c3"/>
 19                 <textElement textAlignment="Center">
 20                     <font isBold="true"/>
 21                 </textElement>
 22                 <text><![CDATA[子报表使用json数据源测试]]></text>
 23             </staticText>
 24         </band>
 25     </title>
 26     <columnHeader>
 27         <band height="20">
 28             <staticText>
 29                 <reportElement x="75" y="0" width="100" height="20" uuid="1c9641be-6be2-486b-91e9-b61394a54cb7"/>
 30                 <box>
 31                     <topPen lineWidth="1.0"/>
 32                     <leftPen lineWidth="1.0"/>
 33                     <bottomPen lineWidth="1.0"/>
 34                     <rightPen lineWidth="1.0"/>
 35                 </box>
 36                 <text><![CDATA[equipment]]></text>
 37             </staticText>
 38             <staticText>
 39                 <reportElement x="175" y="0" width="100" height="20" uuid="61761013-f83f-4847-a308-ebb19beceacd"/>
 40                 <box>
 41                     <topPen lineWidth="1.0"/>
 42                     <leftPen lineWidth="1.0"/>
 43                     <bottomPen lineWidth="1.0"/>
 44                     <rightPen lineWidth="1.0"/>
 45                 </box>
 46                 <text><![CDATA[project]]></text>
 47             </staticText>
 48             <staticText>
 49                 <reportElement x="275" y="0" width="100" height="20" uuid="0620aa0a-e5b6-4c89-940e-cb464d774026"/>
 50                 <box>
 51                     <topPen lineWidth="1.0"/>
 52                     <leftPen lineWidth="1.0"/>
 53                     <bottomPen lineWidth="1.0"/>
 54                     <rightPen lineWidth="1.0"/>
 55                 </box>
 56                 <text><![CDATA[count]]></text>
 57             </staticText>
 58         </band>
 59     </columnHeader>
 60     <detail>
 61         <band height="20">
 62             <textField>
 63                 <reportElement x="75" y="0" width="100" height="20" uuid="24ed5267-5dd7-449c-ab3c-ccb5ceb627a2"/>
 64                 <box>
 65                     <topPen lineWidth="0.75"/>
 66                     <leftPen lineWidth="0.75"/>
 67                     <bottomPen lineWidth="0.75"/>
 68                     <rightPen lineWidth="0.75"/>
 69                 </box>
 70                 <textFieldExpression><![CDATA[$F{equipment}]]></textFieldExpression>
 71             </textField>
 72             <textField>
 73                 <reportElement x="175" y="0" width="100" height="20" uuid="8d50db0b-645c-4ec8-8fb3-579e2bab2b13"/>
 74                 <box>
 75                     <topPen lineWidth="0.75"/>
 76                     <leftPen lineWidth="0.75"/>
 77                     <bottomPen lineWidth="0.75"/>
 78                     <rightPen lineWidth="0.75"/>
 79                 </box>
 80                 <textFieldExpression><![CDATA[$F{project}]]></textFieldExpression>
 81             </textField>
 82             <textField>
 83                 <reportElement x="275" y="0" width="100" height="20" uuid="dee5fca0-ff07-4166-b81a-1035c94518ca"/>
 84                 <box>
 85                     <topPen lineWidth="0.75"/>
 86                     <leftPen lineWidth="0.75"/>
 87                     <bottomPen lineWidth="0.75"/>
 88                     <rightPen lineWidth="0.75"/>
 89                 </box>
 90                 <textFieldExpression><![CDATA[$F{count}]]></textFieldExpression>
 91             </textField>
 92         </band>
 93     </detail>
 94     <summary>
 95         <band height="148" splitType="Stretch">
 96             <subreport>
 97                 <reportElement x="0" y="0" width="555" height="148" uuid="7a8dcc6f-51eb-449b-8887-296672171b47"/>
 98                 <subreportExpression><![CDATA[$P{SUBREPORT_DIR} + "JsonData_subreport1.jasper"]]></subreportExpression>
 99             </subreport>
100         </band>
101     </summary>
102 </jasperReport>
JsonData.jrxml

相关文章:

  • 2021-07-01
  • 2021-08-05
  • 2021-09-28
  • 2021-09-29
  • 2021-09-17
  • 2021-06-27
  • 2021-04-15
  • 2021-09-02
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-21
  • 2018-03-30
  • 2021-09-28
  • 2021-05-02
  • 2021-12-26
相关资源
相似解决方案