How to export JasperReport to HTML?

前端 未结 2 553
不思量自难忘°
不思量自难忘° 2020-12-18 07:14

I have created one .jasper file for my project. I am getting an output in JasperViewer window, but instead of that I want to see it in HTML output form. How can I d

2条回答
  •  渐次进展
    2020-12-18 07:54

    The following code will generate a HTML report:

    private DataSource jasperDataSource;
    private String jasperReportDir;
    
    public void generateHtmlReport(String reportPath, String reportCode, String outputLocation,
                                   Map params) throws Exception
    {
    
        Connection connection=null;
        try
        {
            connection = jasperDataSource.getConnection();
    
            JasperReport  jasperReport = (JasperReport) JRLoader.loadObject(jasperReportDir + "/" + reportPath + "/" + reportCode + ".jasper");
    
            params.put(JRParameter.REPORT_FILE_RESOLVER, new SimpleFileResolver(new File(jasperReportDir + "/" + reportPath)));
    
            JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params, connection);
    
            JasperExportManager.exportReportToHtmlFile(jasperPrint,outputLocation +reportCode+".html");
    
        }
        finally
        {
            if (connection!=null)
            {
                connection.close();
            }
        }
    }
    

    Exports the generated report object into HTML format, placing the result into the second file parameter.

    The images are placed as distinct files inside a directory having the same name as the HTML destination file, plus the "_files" suffix.

提交回复
热议问题