【问题标题】:How to add a tab in Jasper Report TextField如何在 Jasper Report TextField 中添加选项卡
【发布时间】:2017-03-02 06:47:06
【问题描述】:

我想在 Jasper 模板中的文本字段中添加选项卡。下面是我的文本字段。

<staticText>
    <reportElement key="" style="Table_CH" positionType="Float" x="0" y="37" width="802" height="112" uuid="db0d6ece-871a-4e7d-8f74-0abca53b1280"/>
    <textElement markup="styled">
        <font fontName="SansSerif" size="8" isBold="false"/>
        <paragraph lineSpacing="Single"/>
    </textElement>
    <text>
        <![CDATA[ Reader - please note: <li>List element1</li><li>List element2</li>]]>
    </text>
</staticText>

我想在每个列表元素之前放置一个标签。

【问题讨论】:

  • 为什么您的问题没有一个被接受?没有一个答案能解决您的问题吗?
  • 是的@Viki888,仍在努力。如果它有效,我会标记对我有用的正确的。

标签: jasper-reports


【解决方案1】:

在项目符号后添加制表符有几种方式:

  • 使用\t(制表符)sybmol
  • 使用&amp;#09;在html代码中渲染标签
  • 使用&amp;emsp;字符实体

示例

<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="Tabs sample" pageWidth="842" pageHeight="595" orientation="Landscape" whenNoDataType="AllSectionsNoDetail" columnWidth="583" leftMargin="2" rightMargin="10" topMargin="2" bottomMargin="2">
    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
    <title>
        <band height="283">
            <textField>
                <reportElement positionType="Float" x="10" y="20" width="802" height="53" />
                <textElement markup="styled"/>
                <textFieldExpression><![CDATA["List without tabs:<li>List element1</li><li>List element2</li>"]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement positionType="Float" x="10" y="90" width="802" height="53" />
                <textElement markup="styled"/>
                <textFieldExpression><![CDATA["List with basic tab:<li>\tList element1</li><li>\tList element2</li>"]]></textFieldExpression>
            </textField>

            <textField>
                <reportElement positionType="Float" x="10" y="160" width="802" height="53" />
                <textElement markup="html"/>
                <textFieldExpression><![CDATA["List with html tab:<li>&#09;List element1</li><li>&#09;List element2</li>"]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement positionType="Float" x="10" y="230" width="802" height="53" />
                <textElement markup="html"/>
                <textFieldExpression><![CDATA["List with emsp tab:<li>&emsp;List element1</li><li>&emsp;List element2</li>"]]></textFieldExpression>
            </textField>
        </band>
    </title>
</jasperReport>

请注意,我使用 textField 来显示\t 符号。

输出结果

Jaspersoft Studio 中的结果将是:


更多信息:

【讨论】:

    【解决方案2】:

    要在项目符号前添加空格,您可以使用带有真实 html 代码的 html 组件。该组件不提供复杂的 html 代码,仅提供基本代码。

    示例

    <?xml version="1.0" encoding="UTF-8"?>
    <jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="Html component" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
        <property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
        <parameter name="htmlCode" class="java.lang.String">
            <defaultValueExpression><![CDATA["<div>\n" +
                        "<h3>List of elements</h3>\n" +
                        "<ul>\n" +
                        "<li>element1</li>\n" +
                        "<li>element2</li>\n" +
                        "<li>element3</li>\n" +
                        "</ul>\n" +
                        "</div>"]]></defaultValueExpression>
        </parameter>
        <title>
            <band height="742">
                <componentElement>
                    <reportElement x="0" y="0" width="190" height="70"/>
                    <hc:html xmlns:hc="http://jasperreports.sourceforge.net/htmlcomponent" xsi:schemaLocation="http://jasperreports.sourceforge.net/htmlcomponent http://jasperreports.sourceforge.net/xsd/htmlcomponent.xsd" scaleType="RealHeight" horizontalAlign="Left" verticalAlign="Top">
                        <hc:htmlContentExpression><![CDATA[$P{htmlCode}]]></hc:htmlContentExpression>
                    </hc:html>
                </componentElement>
            </band>
        </title>
    </jasperReport>
    

    我使用参数来设置显示列表的 html 代码。您可以使用代码来获得更好的结果。

    输出结果

    Jaspersoft Studio 中的结果将是:


    更多信息:

    【讨论】:

    • net.sf.jasperreports.engine.JRRuntimeException:未知实体jasperreports.sourceforge.net/xsd/htmlcomponent.xsd,未加载。看起来 xsd 文件不存在了。我正在寻找替代方案
    • 你从哪里得到这个错误的?来自 Java 代码?你检查了第一个链接吗?如果使用 Java 代码,您应该在 cp 中添加htmlcomponent.jar
    猜你喜欢
    • 2016-05-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-16
    • 2014-05-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多