如何在DynamicReports和JasperReports中获得相同的样式 [英] How to get same styles in DynamicReports and JasperReports

查看:216
本文介绍了如何在DynamicReports和JasperReports中获得相同的样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想找到具有相同样式的dynamicReports和jasperReports最佳解决方案.我开始使用dynamicReports,但是我发现很难在其中创建异常报告.在iReport图形生成器中执行此操作要容易得多.因此,现在我有50%的报告在Dynamic上运行,而50%的报告在Jasper上运行.

I would like to found best solution for having same styles for dynamicReports and jasperReports. I started to use dynamicReports, however I found it hard to create unusual reports there. It was much easier to do that in iReport graphical builder. So now I have 50% reports which runs on Dynamic and 50% on Jasper.

现在我无法解决样式问题.我已经在Template类中创建了样式,字体等,并将其用于DynamicReports.像这样的魔术之后:

Now I can't resolve style problem. I've created styles, fonts etc in Template class and used it for DynamicReports. After some magic like:

.setName("cellCenterStyle");
template().setColumnStyle(cellStyle)

我可以将其用于碧玉,但这不是完整的解决方案,因为某些选项仍然无法使用,例如:

I was able to use them for jasper, but this is not a full solution as some options still does not work, for example:

.setDetailEvenRowStyle(Template.evenIntensivStyle)

可以动态处理,但是碧玉忽略了.

is working with dynamic, but jasper ignores is.

所以,这个问题:

我可以为动态和碧玉使用相同的样式,结构清晰,没有不必要的魔术"吗? 我希望使用* .css样式之类的解决方案,但会有所帮助.

Could I use same styles for dynamic and jasper with clear structure and without needless "magic". I would prefer solution like *.css styles, but any help would be appreciated.

推荐答案

使用参数来引用样式文件的相对(或绝对)路径.例如,主报告可能包含:

Use a parameter to reference the relative (or absolute) path to the styles file. The main report, for example, might contain:

<template><![CDATA[$P{P_REPORT_STYLES_PATH} + "FontStyle.jrtx"]]></template>
<parameter name="P_REPORT_BASE" class="java.lang.String">
    <defaultValueExpression><![CDATA[""]]></defaultValueExpression>
</parameter>
<parameter name="P_REPORT_RESOURCES_PATH" class="java.lang.String">
    <defaultValueExpression><![CDATA[$P{P_REPORT_BASE} + "resources/"]]></defaultValueExpression>
</parameter>
<parameter name="P_REPORT_STYLES_PATH" class="java.lang.String">
    <defaultValueExpression><![CDATA[$P{P_REPORT_RESOURCES_PATH} + "styles/"]]></defaultValueExpression>
</parameter>

这允许iReport(或Jaspersoft Studio)中的报表引用报表样式的相对路径,例如:

This allows the report in iReport (or Jaspersoft Studio) to reference a relative path to the report styles, such as:

resources/styles/FontStyle.jrtx

此路径相对于报表的.jasper文件位置.

This path is relative to the report's .jasper file location.

然后,在DynamicJasper中,您可以传入报告参数. DynamicJasper中的API调用可能与下面的JasperReports库调用的API调用不匹配,但是应该足够相似,以使想法更完整:

Then, in DynamicJasper, you can pass in a report parameter. The API call in DynamicJasper might not match the API call for the following JasperReports Library call, but it should be sufficiently similar to get the idea across:

    reportParameters.put("P_REPORT_BASE", "/home/user/dev/reports/workspace");
    JasperFillManager.fillReport(..., reportParameters, dataSource);

假定/home/user/dev/reports/workspace.jasper文件的位置以及iReport/Jaspersoft Studio的工作区位置,则DynamicJasper和报表开发环境都将找到并使用相同的样式文件.

Assuming that /home/user/dev/reports/workspace is the location for the .jasper files as well as the workspace location for iReport/Jaspersoft Studio, then both DynamicJasper and the report development environment will find and use the same styles file.

在此示例中,样式文件的完整路径为:

The full path to the styles file, in this example, would be:

/home/user/dev/reports/workspace/resources/styles/FontStyle.jrtx

您的目录路径当然会有所不同.

Your directory paths, of course, will differ.

这时,您可以在两种环境中引用相同的样式.另请参阅:

At this point, you can reference the same styles in both environments. See also:

  • http://community.jaspersoft.com/wiki/styles-template
  • http://dynamicjasper.com/category/docs/howto/styles-templates/
  • https://stackoverflow.com/a/3853401/59087

这篇关于如何在DynamicReports和JasperReports中获得相同的样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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