javaのJasperReportユーティリティを使用することができます。あなたがする必要があることは、あなたが必要としないフィールドをあなたの名前のように固定しながら、あなたが望む数のフィールドを構成し、Javaコードを使ってそのレポートの実行時間を埋めることができる標準的なJasperテンプレート(.jasper拡張ファイル)あなたのユーザー要求オブジェクトを取得したときにすべてのユーザー要求を感じることができます。
ジャスパーにはこのテンプレートをバックエンドで埋め込む機能があり、必要な場所で電子メール応答に添付できるpdf実行時間を生成することができます。
まず
、入力JSON:あなたが使用することができます
{
"userName": "Evil Raat",
"details": {
"email": "[email protected]"
}
}
その後iReportはデザイナーでJSONデータソースを作成し、あなたのファイルでそれを指す(そのデフォルトとして他のすべての詳細を残して)
次jrxmlテンプレートを次のようすると、レポートの中に上記のJSONをレンダリングするために:あなたは、のようなコードを作成することができるよりも
<?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="sample" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="a894078a-929b-4aae-a1d0-46485f0f8835">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<queryString language="json">
<![CDATA[]]>
</queryString>
<field name="userName" class="java.lang.String">
<fieldDescription><![CDATA[userName]]></fieldDescription>
</field>
<field name="userEmail" class="java.lang.String">
<fieldDescription><![CDATA[details.email]]></fieldDescription>
</field>
<title>
<band height="200" splitType="Stretch">
<textField>
<reportElement uuid="3b74775b-4555-43c3-bdf2-1677145c8660" x="0" y="31" width="555" height="20"/>
<textElement textAlignment="Right">
<font fontName="Helvetica" size="12" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[$F{userName}]]></textFieldExpression>
</textField>
<textField>
<reportElement uuid="aa6cc7c8-2ca1-4f0f-92e2-c466083daba0" x="0" y="54" width="555" height="20"/>
<textElement textAlignment="Right">
<font fontName="Helvetica" size="12" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[$F{userEmail}]]></textFieldExpression>
</textField>
</band>
</title>
</jasperReport>
Resource resource = new ClassPathXmlApplicationContext().getResource("classpath:reports/project.jrxml");
JsonDataSource ds = new JsonDataSource(new File("c:\myjson.json"));
jasperDesign = JRXmlLoader.load(resource.getInputStream());
JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, ds);
JasperExportManager.exportReportToPdfFile(jasperPrint, destination+fileName+".pdf");
上記のコードでは、レポートを入力するためのデータソースとして.jsonファイルを使用しています。ランタイムでjsonを生成し、レポートを入力する際に提供することができます。
担当者を見ると、質問する方法がわかります。いくつかのコードマンを投稿してください。 :) –
@ChiragParmar:コードはまだありません。私はこの問題を解決するための最良の方法を探しています。私はHTMLフォームを使用して、それを記入するか、他のものを記入する必要があります。 –