我是否可以将JasperReports查看器集成到我的Swing应用程序中,就像我单击应用程序中的查看报告按钮,然后打开查看器一样。如果是这样,你可以建议我与此集成的代码片段,并在此查看器的另存为类型应限制为PDF,而不是所有其他可用的下载选项过滤器。
请在这方面给我一些建议。
发布于 2010-03-29 16:11:20
是的,Jasper报表提供了一个可用的(虽然简单)报表查看器:
...
JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport...);
JasperViewer.viewReport(jasperPrint);
...最后一行是显示查看器的内容。不过,我不确定您是否可以将可用的输出格式限制为PDF。
发布于 2013-08-13 03:46:37
让我们假设报告包含报告文件(*.jrxml)的名称。此程序将使用mysql数据库中的数据填充报告。我希望这能解决你的问题。
public void generate(String report) { // report will contain the name of your file
try {
InputStream design = getClass().getResourceAsStream(report);
JasperDesign jasperdesing = JRXmlLoader.load(design);
JasperReport jasperReport = JasperCompileManager.compileReport(jasperdesing);
Connection con = ConnectDB.connect();// connect function in ConnectDB calss is used to connect to the database
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, null, con);
JasperViewer.viewReport(jasperPrint, false);
} catch (Exception e) {
System.out.println("Exception " + e);
}
}
public class ConnectDB {
public static Connection con = null;
public static Connection connect(){
try{
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql:///dbname","username","password");
}catch(Exception e){
System.out.println();
}
return con;
}}
https://stackoverflow.com/questions/2536281
复制相似问题