我使用以下代码打印报告:
JasperPrint jasperPrint = null;
try {
JasperCompileManager.compileReportToFile("C:\\Nevro\\reports\\salesDetails.jrxml");
jasperPrint = JasperFillManager.fillReport("C:\\Nevro\\reports\\salesDetails.jasper", new HashMap(),
new JRTableModelDataSource(itemTable.getModel()));
JasperViewer jasperViewer = new JasperViewer(jasperPrint);
jasperViewer.setVisible(true);
} catch (JRException ex) {
Logger.getLogger(Invoice.class.getName()).log(Level.SEVERE, null, ex);
}在位置C:\Nevro\reports\中,我创建了salesDetails.jrxml。然后,在Java代码中,我读取并编译该文件。我希望将编译后的文件创建为salesDetails.jasper,但它只创建null.jasper。
有人能给我一个解决办法吗?
发布于 2016-06-23 06:52:23
文件名是由Jasper库中的这一行代码生成的:
File destFile = new File(sourceFile.getParent(), jasperDesign.getName() + ".jasper");它接受jrxml文件的路径,并根据报表的名称(在XML中配置)生成输出文件。在您的示例中,报告没有名称,因此您将得到null.jasper。
发布于 2016-06-23 07:09:23
您还可以显式地给出.jasper文件的名称,
JasperCompileManager.compileReportToFile(
our_jasper_template.jrxml",//the path to the jrxml file to compile
our_compiled_template.jasper");//the path and name we want to save the com因此,上述代码将在存在.jasper文件的同一位置生成.jrxml文件。
https://stackoverflow.com/questions/37984038
复制相似问题