如何将JasperReport导出为HTML? [英] How to export JasperReport to HTML?

查看:1254
本文介绍了如何将JasperReport导出为HTML?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为我的项目创建了一个 .jasper 文件。我在JasperViewer窗口中获得了一个输出,但是我希望在HTML输出窗体中看到它。我该怎么做?

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 do that?

推荐答案

以下代码将生成HTML报告:

The following code will generate a HTML report:

private DataSource jasperDataSource;
private String jasperReportDir;

public void generateHtmlReport(String reportPath, String reportCode, String outputLocation,
                               Map<String, Object> 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();
        }
    }
}

将生成的报告对象导出到HTML格式,将结果放入第二个文件参数。

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

图像作为不同的文件放在与HTML目标文件同名的目录中,加上 _files后缀。

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

这篇关于如何将JasperReport导出为HTML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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