JasperViewer - 如何设置文件名并设置扩展名(格式)? [英] JasperViewer - How to set file name and set the extension (format)?

查看:410
本文介绍了JasperViewer - 如何设置文件名并设置扩展名(格式)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Swing 框架和 JasperReports 开发 Java 基于桌面的应用程序进行报告。我有一些问题,当 JasperViewer 出现时我想保存报告。

I am developing Java desktop based application using Swing framework and JasperReports for reporting. I have some problems, when JasperViewer comes up and I want to save the report.

如何在保存对话框中设置文件名(默认为空白)以及如何仅限制 Pdf 格式?

How can I set the name of the file (default is blank) in the save dialog and how to limit only Pdf format?

这是我的代码:

JRBeanCollectionDataSource beanCollection=new JRBeanCollectionDataSource(matakuliahs);

Map<String,Object> map=new HashMap<String, Object>();
map.put("namaMahasiswa", mahasiswa.getNama());

InputStream input=getClass().getResourceAsStream("/reportsederhana/reportsederhana.jrxml");
JasperDesign design=JRXmlLoader.load(input);
JasperReport report=JasperCompileManager.compileReport(design);
JasperPrint jasperPrint=JasperFillManager.fillReport(report, map, beanCollection);
jasperPrint.setName("Laporan "+mahasiswa.getNama()); // it doesn't give the name
JasperViewer.viewReport(jasperPrint,false);


推荐答案

用于设置要保存的默认扩展名,一个想法是你需要以某种方式从 JasperViewer (实例)获取 JRViewer 实例然后,在void JRViewer 实例,您可以设置一些保存贡献。看看 JRViewer.setSaveContributors(JRSaveContributor [] saveContribs)

For setting the default extension(s) to save to, one idea is that you need to somehow get the JRViewer instance from a JasperViewer (instance) and then, on the void JRViewer instance, you can set some save contributions. Have a look at JRViewer.setSaveContributors(JRSaveContributor[] saveContribs).

For设置文件名,我不完全确定,但看看 JRViewer.JRViewer(String,boolean)

For setting the file name, i am not entirely sure, but have a look at JRViewer.JRViewer(String, boolean).

另请查看 JRViewer JasperViewer 源代码,它可能会派上用场。

Also check the JRViewer and the JasperViewer source code, it may come in handy.

这篇关于JasperViewer - 如何设置文件名并设置扩展名(格式)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆