我正在使用Jasper Report
使用Java
。
我有
主要报告contains
子报告contains
子报告
我得到的问题是主报告显示子报告,但子报告未显示其子报告。
mainReport.jrxml
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version last-->
<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="demo" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="381b6277-2f70-46c8-9c37-6c8ac5f47857">
<property name="net.sf.jasperreports.export.csv.exclude.origin.band.1" value="pageHeader"/>
<property name="net.sf.jasperreports.export.csv.exclude.origin.band.2" value="pageFooter"/>
<property name="net.sf.jasperreports.export.csv.exclude.origin.band.summary" value="summary"/>
<property name="net.sf.jasperreports.export.xls.exclude.origin.band.1" value="pageHeader"/>
<property name="net.sf.jasperreports.export.xls.exclude.origin.band.2" value="pageFooter"/>
<property name="net.sf.jasperreports.export.xls.exclude.origin.keep.first.band.2" value="columnHeader"/>
<property name="net.sf.jasperreports.export.xls.remove.empty.space.between.rows" value="true"/>
<property name="net.sf.jasperreports.export.xls.remove.empty.space.between.columns" value="true"/>
<property name="net.sf.jasperreports.export.xls.exclude.origin.band.summary" value="summary"/>
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
<parameter name="subreport" class="net.sf.jasperreports.engine.JasperReport"/>
<parameter name="title" class="java.lang.String"/>
<parameter name="username" class="java.lang.String"/>
<parameter name="logo" class="java.io.InputStream"/>
<queryString>
<![CDATA[]]>
</queryString>
<field name="resultEntities" class="java.util.List"/>
<field name="sponsorName" class="java.lang.String"/>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="42" splitType="Stretch">
<textField>
<reportElement uuid="19b3ea11-765d-4e11-b823-6f2dffe149ef" x="200" y="2" width="310" height="30"/>
<textElement textAlignment="Center">
<font size="18" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[$P{title}]]></textFieldExpression>
</textField>
<image onErrorType="Blank">
<reportElement uuid="827deabf-52f4-4e2d-a700-cb25e0d17f8d" x="0" y="-8" width="200" height="50"/>
<imageExpression><![CDATA[$P{logo}]]></imageExpression>
</image>
</band>
</title>
<pageHeader>
<band height="17" splitType="Stretch"/>
</pageHeader>
<columnHeader>
<band height="21" splitType="Stretch"/>
</columnHeader>
<detail>
<band height="130" splitType="Stretch">
<staticText>
<reportElement uuid="e09c8f6a-0d7a-44a7-b050-5ae9e3d6cd1a" mode="Opaque" x="0" y="0" width="110" height="20" forecolor="#000000" backcolor="#FFFFFF"/>
<textElement>
<font size="11" isBold="true"/>
</textElement>
<text><![CDATA[Sponsor Name:]]></text>
</staticText>
<textField>
<reportElement uuid="5781f4ef-2af7-4144-82ff-27cc707099b7" x="120" y="0" width="277" height="20"/>
<textElement>
<font size="12" isBold="false"/>
</textElement>
<textFieldExpression><![CDATA[$F{sponsorName}]]></textFieldExpression>
</textField>
<subreport>
<reportElement uuid="381339b0-ca91-41f6-a625-4281afd9e52a" x="0" y="80" width="551" height="46"/>
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{resultEntities})]]></dataSourceExpression>
<subreportExpression><![CDATA[$P{subreport}]]></subreportExpression>
</subreport>
<textField>
<reportElement uuid="95763471-cdf9-4131-9496-05b9121ec189" x="120" y="20" width="277" height="20"/>
<textElement>
<font size="12" isBold="false"/>
</textElement>
<textFieldExpression><![CDATA[$P{username}]]></textFieldExpression>
</textField>
<staticText>
<reportElement uuid="08ea8903-a99a-4e09-84c4-012df07d73df" mode="Opaque" x="0" y="20" width="110" height="20" forecolor="#000000" backcolor="#FFFFFF"/>
<textElement>
<font size="11" isBold="true"/>
</textElement>
<text><![CDATA[Username:]]></text>
</staticText>
</band>
<band height="111">
<break>
<reportElement uuid="58154019-f6fe-4e30-bd85-e959cfb79c8c" isPrintRepeatedValues="false" x="0" y="4" width="100" height="1"/>
</break>
</band>
</detail>
<pageFooter>
<band height="20" splitType="Stretch">
<textField>
<reportElement uuid="247f9650-33e1-49aa-9d48-2b53a63412ec" x="433" y="0" width="80" height="20"/>
<textElement textAlignment="Right">
<font size="10" isBold="false"/>
</textElement>
<textFieldExpression><![CDATA["Page "+$V{PAGE_NUMBER}+" of"]]></textFieldExpression>
</textField>
<textField evaluationTime="Report">
<reportElement uuid="99aea93f-321e-49d5-84e9-356d3bf3d6a2" x="513" y="0" width="40" height="20"/>
<textElement>
<font size="10" isBold="false"/>
</textElement>
<textFieldExpression><![CDATA[" " + $V{PAGE_NUMBER}]]></textFieldExpression>
</textField>
<textField pattern="EEEEE dd MMMMM yyyy">
<reportElement uuid="8be76444-ca98-43a1-be6e-8ccc5b581905" x="0" y="0" width="197" height="20"/>
<textElement>
<font size="10" isBold="false"/>
</textElement>
<textFieldExpression><![CDATA[new java.util.Date()]]></textFieldExpression>
</textField>
</band>
</pageFooter>
<summary>
<band height="50" splitType="Stretch">
<staticText>
<reportElement uuid="e09c8f6a-0d7a-44a7-b050-5ae9e3d6cd1a" x="80" y="20" width="330" height="30" forecolor="#008080"/>
<textElement textAlignment="Center" rotation="None" markup="styled">
<font size="18" isBold="true"/>
</textElement>
<text><![CDATA[End of Report]]></text>
</staticText>
</band>
</summary>
</jasperReport>
子报表-1
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version last-->
<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="demo_address" pageWidth="555" pageHeight="802" columnWidth="555" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" uuid="5e467d97-e040-4786-bd94-5625de268971">
<style name="Title" fontName="Arial" fontSize="26" isBold="true" pdfFontName="Helvetica-Bold"/>
<style name="SubTitle" forecolor="#666666" fontName="Arial" fontSize="18"/>
<style name="Column header" forecolor="#666666" fontName="Arial" fontSize="12" isBold="true"/>
<style name="Detail" fontName="Arial" fontSize="12"/>
<parameter name="subreport2" class="net.sf.jasperreports.engine.JasperReport"/>
<field name="iTID" class="java.lang.String"/>
<field name="allocationNumber" class="java.lang.String"/>
<field name="partDescription" class="java.lang.String"/>
<field name="serialNumber" class="java.lang.String"/>
<field name="partName" class="java.lang.String"/>
<field name="stockType" class="java.lang.String"/>
<field name="dispatchLocation" class="java.lang.String"/>
<field name="partNumberSubEntities" class="java.util.List"/>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band splitType="Stretch"/>
</title>
<pageHeader>
<band height="5" splitType="Stretch"/>
</pageHeader>
<columnHeader>
<band height="50">
<staticText>
<reportElement uuid="0fd796af-139d-45ff-8eee-fad16f65c526" x="0" y="5" width="120" height="40" backcolor="#CFCFCF"/>
<box>
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font fontName="SansSerif" size="9" isBold="true" isItalic="false" isUnderline="false"/>
<paragraph lineSpacing="Proportional"/>
</textElement>
<text><![CDATA[Option/Part No]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="231" splitType="Stretch">
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement uuid="77b324a2-4b82-4988-acf6-d93b68adfa1a" x="0" y="0" width="120" height="20"/>
<box>
<bottomPen lineWidth="0.5"/>
</box>
<textElement textAlignment="Justified">
<paragraph lineSpacing="Proportional"/>
</textElement>
<textFieldExpression><![CDATA[$F{partName}]]></textFieldExpression>
</textField>
<subreport>
<reportElement uuid="381339b0-ca91-41f6-a625-4281afd9e52a" positionType="Float" x="0" y="20" width="551" height="46"/>
<subreportParameter name="subreport2"/>
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{partNumberSubEntities})]]></dataSourceExpression>
<subreportExpression><![CDATA[$P{subreport2}]]></subreportExpression>
</subreport>
</band>
</detail>
<pageFooter>
<band splitType="Stretch"/>
</pageFooter>
<summary>
<band splitType="Stretch"/>
</summary>
</jasperReport>
子报告
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version last-->
<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="demo_address" pageWidth="555" pageHeight="802" columnWidth="555" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" uuid="5e467d97-e040-4786-bd94-5625de268971">
<style name="Title" fontName="Arial" fontSize="26" isBold="true" pdfFontName="Helvetica-Bold"/>
<style name="SubTitle" forecolor="#666666" fontName="Arial" fontSize="18"/>
<style name="Column header" forecolor="#666666" fontName="Arial" fontSize="12" isBold="true"/>
<style name="Detail" fontName="Arial" fontSize="12"/>
<field name="iTID" class="java.lang.String"/>
<field name="allocationNumber" class="java.lang.String"/>
<field name="partDescription" class="java.lang.String"/>
<field name="serialNumber" class="java.lang.String"/>
<field name="partName" class="java.lang.String"/>
<field name="stockType" class="java.lang.String"/>
<field name="dispatchLocation" class="java.lang.String"/>
<field name="partNumberSubEntities" class="java.util.List"/>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band splitType="Stretch"/>
</title>
<pageHeader>
<band height="5" splitType="Stretch"/>
</pageHeader>
<columnHeader>
<band height="50">
<staticText>
<reportElement uuid="0fd796af-139d-45ff-8eee-fad16f65c526" x="0" y="0" width="70" height="45" backcolor="#CFCFCF"/>
<box>
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font fontName="SansSerif" size="9" isBold="true" isItalic="false" isUnderline="false"/>
<paragraph lineSpacing="Proportional"/>
</textElement>
<text><![CDATA[Stock Type]]></text>
</staticText>
<staticText>
<reportElement uuid="0fd796af-139d-45ff-8eee-fad16f65c526" x="70" y="0" width="80" height="45" backcolor="#CFCFCF"/>
<box>
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font fontName="SansSerif" size="9" isBold="true" isItalic="false" isUnderline="false"/>
<paragraph lineSpacing="Proportional"/>
</textElement>
<text><![CDATA[Option/Part No]]></text>
</staticText>
<staticText>
<reportElement uuid="0fd796af-139d-45ff-8eee-fad16f65c526" x="150" y="0" width="86" height="45" backcolor="#CFCFCF"/>
<box>
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font fontName="SansSerif" size="9" isBold="true" isItalic="false" isUnderline="false"/>
<paragraph lineSpacing="Proportional"/>
</textElement>
<text><![CDATA[Description]]></text>
</staticText>
<staticText>
<reportElement uuid="0fd796af-139d-45ff-8eee-fad16f65c526" x="236" y="0" width="60" height="45" backcolor="#CFCFCF"/>
<box>
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font fontName="SansSerif" size="9" isBold="true" isItalic="false" isUnderline="false"/>
<paragraph lineSpacing="Proportional"/>
</textElement>
<text><![CDATA[TID]]></text>
</staticText>
<staticText>
<reportElement uuid="0fd796af-139d-45ff-8eee-fad16f65c526" x="296" y="0" width="80" height="45" backcolor="#CFCFCF"/>
<box>
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font fontName="SansSerif" size="9" isBold="true" isItalic="false" isUnderline="false"/>
<paragraph lineSpacing="Proportional"/>
</textElement>
<text><![CDATA[Serial No]]></text>
</staticText>
<staticText>
<reportElement uuid="0fd796af-139d-45ff-8eee-fad16f65c526" x="376" y="0" width="74" height="45" backcolor="#CFCFCF"/>
<box>
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font fontName="SansSerif" size="9" isBold="true" isItalic="false" isUnderline="false"/>
<paragraph lineSpacing="Proportional"/>
</textElement>
<text><![CDATA[Allocation No]]></text>
</staticText>
<staticText>
<reportElement uuid="fb4084da-6bd7-4534-8f2e-bf13a976e52f" x="450" y="0" width="104" height="45" backcolor="#CFCFCF"/>
<box>
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font fontName="SansSerif" size="9" isBold="true" isItalic="false" isUnderline="false"/>
<paragraph lineSpacing="Proportional"/>
</textElement>
<text><![CDATA[Dispatch Location]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="27" splitType="Stretch">
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement uuid="77b324a2-4b82-4988-acf6-d93b68adfa1a" x="0" y="0" width="70" height="20"/>
<box>
<bottomPen lineWidth="0.5"/>
</box>
<textElement textAlignment="Left">
<paragraph lineSpacing="Proportional"/>
</textElement>
<textFieldExpression><![CDATA[$F{stockType}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement uuid="77b324a2-4b82-4988-acf6-d93b68adfa1a" x="70" y="0" width="80" height="20"/>
<box>
<bottomPen lineWidth="0.5"/>
</box>
<textElement textAlignment="Justified">
<paragraph lineSpacing="Proportional"/>
</textElement>
<textFieldExpression><![CDATA[$F{partName}]]></textFieldExpression>
</textField>
</band>
</detail>
<columnFooter>
<band height="227" splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band splitType="Stretch"/>
</pageFooter>
<summary>
<band splitType="Stretch"/>
</summary>
</jasperReport>
要导出的Java代码
Map<String, Object> map = new HashMap<String, Object>();
map.put("title", title);
map.put("username", user);
map.put("usergroup", usergroup);
map.put("startDate", startDate);
map.put("endDate", endDate);
map.put("sponsorName", "Barclays");
map.put("logo", GenericExporter.class.getResourceAsStream("/res/logo.gif"));
// get collection datasource
JRBeanCollectionDataSource jrBeanCollectionDataSource = new JRBeanCollectionDataSource(resultObjects);
// compile master and sub
InputStream masterReportStream = GenericExporter.class.getResourceAsStream(masterReport.getFilename());
InputStream subReportStream = GenericExporter.class.getResourceAsStream(subReport.getFilename());
InputStream subsubstream = GenericExporter.class.getResourceAsStream("/res/DetailedStockReportSub_Sub.jrxml");
JasperReport masterCompile = JasperCompileManager.compileReport(JRXmlLoader.load(masterReportStream));
JasperReport subCompiled = JasperCompileManager.compileReport(JRXmlLoader.load(subReportStream));
JasperReport subsubcompiled = JasperCompileManager.compileReport(JRXmlLoader.load(subsubstream));
// put sub report in map
map.put("subreport", subCompiled);
map.put("subreport2", subsubcompiled);
// fill report
JasperPrint jasperFillRepor = JasperFillManager.fillReport(masterCompile, map, jrBeanCollectionDataSource);
JRPdfExporter jrPdfExporter = new JRPdfExporter();
jrPdfExporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperFillRepor);
jrPdfExporter.setParameter(JRExporterParameter.OUTPUT_STREAM, outpuStream);
// run export
jrPdfExporter.exportReport();
return new ByteArrayInputStream(outpuStream.toByteArray());
代码执行正常,没问题。但是,如果我查看PDF,它不包含子报告中的表格。
任何帮助将不胜感激。
答案 0 :(得分:2)
Jasper
是废话。表格没有适当的控制权。它甚至无法与子报告一起正常工作。
我最终使用了iTEXt,它更好,你可以更好地控制你想要显示的数据。