簡體   English   中英

從報告外部將值設置為碧玉報告

[英]set values from outside the report to a jasper report

我將使用jasper報告生成報告。 為此,我的計划是

  • 使用iReport工具根據需要創建jrxml文件。
  • 從報表外部設置所需的值。 (我的意思是,如果我的java程序中有一個名為name="james"變量,則將該變量設置為報表中的文本字段)
  • 然后創建報告並生成pdf。

我需要知道的是這種可能性。 我可以將變量設置到jrxml文件的字段中嗎? 如果可能,我該怎么辦?

我需要知道的是這種可能性。 我可以將變量設置到jrxml文件的字段中嗎?

基本上是。

您需要在報表中將參數定義為“參數”類型,然后在表格上以$P{...}格式提供參數作為“文本字段表達式”

Prameters

然后,當您要填寫報告時,您需要做的是創建某種類型的Map ,該Map的每個鍵應為您在報告中定義的參數名稱,例如...

Map<String, Object> mapParameters = new HashMap<String, Object>(5);
mapParameters.put("USER_NAME", name);

JasperPrint print = JasperFillManager.fillReport(report, mapParameters);

它解決了!

para.put(<key>,<value>);
para.put(<key>,<value>);
para.put(<key>,<value>);

JasperFillManager.fillReportToFile(jr, para, new JRemptyDataSource());

如果您不編寫新的JRemptyDataSource(),則會顯示一條消息,指出該文檔沒有頁面,並且在報表內創建一個字段,並在字段表達式中放入您的參數(參數名稱應具有相同的鍵值)

我得到了答案

     parameters.put("ReportTitle", "List of Contacts");
     parameters.put("Author", "Prepared By Manisha");

     JasperPrint print = JasperFillManager.fillReport(sourceFileName, parameters, new JREmptyDataSource());

     JRPdfExporter exporter = new JRPdfExporter();
     exporter.setExporterInput(new SimpleExporterInput(print));
     exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(outFileNamePDF));
     SimplePdfExporterConfiguration configuration = new SimplePdfExporterConfiguration();
     configuration.setMetadataAuthor("Petter");  //why not set some config as we like
     exporter.setConfiguration(configuration);
     exporter.exportReport();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM