JasperReports HTML 报告分页

发布于 2024-12-18 04:02:54 字数 185 浏览 0 评论 0 原文

我正在使用 JasperReportsSpring MVC 3 生成一个 HTML 报告,用于在 Web 应用程序中显示表数据。

JasperReports 是否提供某种分页方法?或者,是否可以使用某些 Spring MVC 实用程序对生成的报告中的数据进行分页?

I'm generating an HTML report for showing table data in a web application, using JasperReports and Spring MVC 3.

Does JasperReports provide some kind of pagination method? Or, is it possible to paginate data in the generated report using some Spring MVC utilities?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

苦笑流年记忆 2024-12-25 04:02:54

是的,JasperReports提供了一些分页方法。

您可以设置此导出器参数:

JRHtmlExporterParameter.BETWEEN_PAGES_HTML
JRHtmlExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS

BETWEEN_PAGES_HTML导出器参数接受 >java.lang.String 在导出为 HTML 格式时替换默认页面分隔符。

当设置为 Boolean.TRUE 时,IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS 导出器
参数确保生成的 HTML 表格上的所有空行都被折叠。

PROPERTY_ONE_PAGE_PER_SHEET未设置时,所有文档页面将打印到一张纸上。分页符显示为页面之间的补充空行。

您可以阅读本指南了解更多信息并探索此示例 Struts

您可以使用 IS_IGNORE_PAGINATION 内置报表参数或 isIgnorePagination 报表的模板属性。

您可以将此参数设置为避免将文档分成多页。

您可以使用 JasperReports API - JasperDesign.setIgnorePagination(布尔ignorePagination)


补充

SO 的相关帖子:Jasper Reports 是否合适在 Web 应用程序中显示报告的解决方案?

您可以查看 $JASPERREPORTS_DIR$\demo\samples\nopagebreak 文件夹中的示例报告(分布式与JasperReports包)。

Yes, the JasperReports provides some pagination methods.

You can set this exporters parameters:

JRHtmlExporterParameter.BETWEEN_PAGES_HTML
JRHtmlExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS

The BETWEEN_PAGES_HTML exporter parameter accepts a java.lang.String to replace the default page separator when exporting to HTML format.

When set to Boolean.TRUE, the IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS exporter
parameter ensures that all empty rows on the resulting HTML table are collapsed.

When PROPERTY_ONE_PAGE_PER_SHEET is not set, all document pages will be printed out into a single sheet. Page breaks appear as supplementary empty rows between pages.

You can read this guide for more information and explore this example for Struts.

You can use the IS_IGNORE_PAGINATION built-in report parameter or isIgnorePagination report's template property.

You can set this parameters to avoid breaking documents into multiple pages.

You can use JasperReports API - JasperDesign.setIgnorePagination(boolean ignorePagination) method.


Additions:

The related post on SO: Is Jasper Reports the appropriate solution to display reports in a web application?

You can look at the sample report in $JASPERREPORTS_DIR$\demo\samples\nopagebreak folder (distributed with JasperReports pack).

じ违心 2024-12-25 04:02:54

我看过这个例子: http:// helptodeveloper.blogspot.com/2010/02/jasper-reports-with-pagination.html 并检查了包含在JasperReports 包(特别是 viewer.jsp)。

我尝试使用 Spring MVC 实现类似的目标。

在我的控制器类中,我以这种方式修改了我的请求处理方法

@RequestMapping("/report")
public ModelAndView showHtmlReport(HttpServletRequest request,
        HttpServletResponse response,
        @RequestParam(value = "page", required = false) String pageIndex,
        ModelMap model) {

    // do something...

    if (StringUtils.isNotBlank(pageIndex)
            && StringUtils.isNumeric(pageIndex)) {
        model.put("page_index", new Integer(pageIndex));
    }

    // do something else...

    return new ModelAndView("htmlReport", model);
}

然后我扩展了 Spring 提供的标准 JasperReportsHtmlView,覆盖renderReport 方法:

@Override
protected void renderReport(JasperPrint populatedReport,
        Map<String, Object> model, HttpServletResponse response)
        throws Exception {

    // check something...

    if (model.containsKey("page_index")) {
        Map<net.sf.jasperreports.engine.JRExporterParameter, Object> expParams = 
                this.getConvertedExporterParameters();
        expParams.put(
                net.sf.jasperreports.engine.JRExporterParameter.PAGE_INDEX,
                model.get("page_index"));
    }

    // check something else...

    super.renderReport(populatedReport, model, response);
}

注意: 我实际上出于另一个原因扩展了 html-view 类( JasperReports 的 html 报告中未显示图像 ),但按照相同的方法我也解决了这个问题。

注意pt.2:我是Spring框架的新手,所以如果我的答案不完全正确......尝试理解我! :)

I've had a look at this example: http://helptodeveloper.blogspot.com/2010/02/jasper-reports-with-pagination.html and checked the webapp demo included in the JasperReports package (in particular the viewer.jsp).

I've tried to achieve something similar using Spring MVC.

In my controller class I've modified my request-handling method this way:

@RequestMapping("/report")
public ModelAndView showHtmlReport(HttpServletRequest request,
        HttpServletResponse response,
        @RequestParam(value = "page", required = false) String pageIndex,
        ModelMap model) {

    // do something...

    if (StringUtils.isNotBlank(pageIndex)
            && StringUtils.isNumeric(pageIndex)) {
        model.put("page_index", new Integer(pageIndex));
    }

    // do something else...

    return new ModelAndView("htmlReport", model);
}

Then I've extended the standard JasperReportsHtmlView provided by Spring, overriding the renderReport method:

@Override
protected void renderReport(JasperPrint populatedReport,
        Map<String, Object> model, HttpServletResponse response)
        throws Exception {

    // check something...

    if (model.containsKey("page_index")) {
        Map<net.sf.jasperreports.engine.JRExporterParameter, Object> expParams = 
                this.getConvertedExporterParameters();
        expParams.put(
                net.sf.jasperreports.engine.JRExporterParameter.PAGE_INDEX,
                model.get("page_index"));
    }

    // check something else...

    super.renderReport(populatedReport, model, response);
}

NOTE: I actually extended the html-view class for another reason ( Images not shown in JasperReports' html report ), but following the same approach I solved also this problem.

NOTE pt.2: I'm new to Spring Framework, so if my answer is not completely correct... Try to understand me! :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文