代码之家  ›  专栏  ›  技术社区  ›  Jamie Love

JasperReports中的外部风格

  •  21
  • Jamie Love  · 技术社区  · 16 年前

    我正在开发一个包含大量报告的系统,使用 JasperReports . 其中一个较新的功能是可以定义报告的样式。

    从可用的文档中,我相信有一些方法可以让外部文件定义要使用的样式,您可以在jasper报告中引用这些样式。这允许多个报告使用单一样式。

    3 回复  |  直到 8 年前
        1
  •  30
  •   Petter Friberg Onceler    4 年前

    使用 JasperReport templates .jrtx ,可能看起来与此类似( styles.jrtx ):

    <?xml version="1.0"?>
    <!DOCTYPE jasperTemplate
      PUBLIC "-//JasperReports//DTD Template//EN"
      "http://jasperreports.sourceforge.net/dtds/jaspertemplate.dtd">
    
    <jasperTemplate>
        <style name="Report Title" isDefault="false" hAlign="Center" fontSize="24" isBold="true"/>
        <style name="Heading 1" isDefault="false" fontSize="18" isBold="true"/>
        <style name="Heading 2" isDefault="false" fontSize="14" isBold="true"/>
    </jasperTemplate>
    

    然后在你的 .jrxml 文件,将其作为模板包含:

    ...
    <template><![CDATA["styles.jrtx"]]></template>
    ...
    

    iReport也理解这一点,因此您的样式被正确地导入并显示在iReport中(尽管我确实注意到有时它不会在需要重新加载或重新编译时拾取它们)。

        2
  •  9
  •   Donal Donal    16 年前

    <template> 元素,使用在运行时传递到报表中的参数

    <parameter name="TEMPLATE_FILE" isForPrompting="false" class="java.lang.String"/>

    <template><![CDATA[$P{TEMPLATE_FILE}]]></template>

        3
  •  5
  •   roshani    14 年前

    我喜欢分享我在Jasper报表中使用样式的学习,我认为这对像我这样的报表设计师非常有用,这是从Bilal Siddiqui的一本名为JasperReport Development cookbook的书中学到的。我喜欢这本书,并发现展示风格的方式多种多样,如:


    • 创建新报告时只需选择样式,并定义文本、线条和矩形的样式。样式文件将存储为.jrtx文件。

    • 将其导入报表中
      在报告中导入样式时,有三块信息。

    <template><![CDATA["C:\\ BigBoldRedTemplate.jrtx"]]></template>
    

    步骤二每次使用样式模板将样式应用于报表元素时 <reportElement> 标签的创建如下所示:

    //style applied to a rectangle
    <rectangle radius="10">
        <reportElement style="BigBoldRed" mode="Transparent" x="0" y="0" width="555" height="44"/>
    </rectangle>
    //style applied to a the text field
    <staticText>
            <reportElement style="BigBoldRed" x="0" y="0" width="555" height="66"/>
            <textElement textAlignment="Center" verticalAlignment="Middle"/>
            <text><![CDATA[Monthly Customer Invoices]]></text>
    </staticText>
    

    • 使用HTML的强大功能设计报告样式
      例如,您的文本字段具有以下表达式,其中包括HTML标记(即。 <li> )您希望HTML标记在报表设计中起作用:
    "<li>"+"Invoice # "+$F{InvoiceID}+", "+
    

    $F{CustomerName}+“已购买 \$“+$F{InvoiceValue}+”+“+”

    解决方案很简单,只需将文本字段的Markup属性设置为Styled,并将其设置为Styled。