Java 将报告外部的值设置为jasper报告
我将使用jasper reports生成报告。为此,我的计划是Java 将报告外部的值设置为jasper报告,java,jasper-reports,Java,Jasper Reports,我将使用jasper reports生成报告。为此,我的计划是 使用iReport工具根据需要创建jrxml文件 从报告外侧设置所需的值。(我的意思是,如果我在java程序中有一个名为name=“james”的变量,请将该变量设置为报告中的文本字段) 然后创建报告并生成pdf 我需要知道的是这种可能性。我可以在jrxml文件中的字段中设置变量吗?如果可能的话,我怎么做 我需要知道的是这种可能性。我可以将变量设置到jrxml文件中的字段中吗 基本上,是的 您需要在报表中将参数定义为“参数”类型
- 使用
工具根据需要创建iReport
文件jrxml
- 从报告外侧设置所需的值。(我的意思是,如果我在
程序中有一个名为java
的变量,请将该变量设置为报告中的文本字段)name=“james”
- 然后创建报告并生成pdf
jrxml
文件中的字段中设置变量吗?如果可能的话,我怎么做
我需要知道的是这种可能性。我可以将变量设置到jrxml文件中的字段中吗
基本上,是的
您需要在报表中将参数定义为“参数”类型,然后以$p{…}
然后,当您想要填充报告时,您需要做的是创建某种类型的映射
,映射中的每个键都应该是您在报告中定义的参数的名称,例如
Map<String, Object> mapParameters = new HashMap<String, Object>(5);
mapParameters.put("USER_NAME", name);
JasperPrint print = JasperFillManager.fillReport(report, mapParameters);
Map-mapParameters=新的HashMap(5);
mapParameters.put(“用户名”,名称);
JasperPrint print=JasperFillManager.fillReport(报告,映射参数);
我需要知道的是这种可能性。我可以将变量设置到jrxml文件中的字段中吗
基本上,是的
您需要在报表中将参数定义为“参数”类型,然后以$p{…}
然后,当您想要填充报告时,您需要做的是创建某种类型的映射
,映射中的每个键都应该是您在报告中定义的参数的名称,例如
Map<String, Object> mapParameters = new HashMap<String, Object>(5);
mapParameters.put("USER_NAME", name);
JasperPrint print = JasperFillManager.fillReport(report, mapParameters);
Map-mapParameters=新的HashMap(5);
mapParameters.put(“用户名”,名称);
JasperPrint print=JasperFillManager.fillReport(报告,映射参数);
问题解决了
para.put(<key>,<value>);
para.put(<key>,<value>);
para.put(<key>,<value>);
JasperFillManager.fillReportToFile(jr, para, new JRemptyDataSource());
para.put(,);
第12段付诸表决(,);
第12段付诸表决(,);
JasperFillManager.fillReportToFile(jr,para,新的jrpemptyDataSource());
如果不编写新的JREPTYDATASOURCE(),将显示一条消息,说明文档没有页面
在报告中创建一个字段,并在字段表达式中放入参数(参数名称应具有相同的键值)它已解决
para.put(<key>,<value>);
para.put(<key>,<value>);
para.put(<key>,<value>);
JasperFillManager.fillReportToFile(jr, para, new JRemptyDataSource());
para.put(,);
第12段付诸表决(,);
第12段付诸表决(,);
JasperFillManager.fillReportToFile(jr,para,新的jrpemptyDataSource());
如果不编写新的JREPTYDATASOURCE(),将显示一条消息,说明文档没有页面
在报告中创建一个字段,在字段表达式中输入参数(参数名称应具有相同的键值)我得到了答案
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();
我得到了答案
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();