首页 文章

如何使用段落文本之间的字段创建报表?

提问于
浏览
1

我的报告如下 .
Report

在显示的报告中,黑色文本是静态的,RED中的文本是由java动态替换为某些值的字段 .

在上图中,第1行和第2行我没有问题 .

但对于这段我不知道该用什么?我应该使用静态文本框还是文本字段?如果我使用部分静态文本框和部分动态,它变得笨拙并且难以保持行间距 .

因此,请告知如何在jasper studio 5.6中设计以下报告 .

1 回答

  • 1

    在文本上使用 textField 然后使用字符串连接,当需要数字格式时使用NumberFormat APIDecimalFormat API

    如果你需要断行,设置粗体文本你可以使用html来实现这一点,方法是在 textElement 上设置 markup="html"

    Example

    <?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="test" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="0ef33a9d-fd2b-46cc-9ec4-c6906db8097b">
        <property name="ireport.zoom" value="1.0"/>
        <property name="ireport.x" value="0"/>
        <property name="ireport.y" value="0"/>
        <parameter name="testNumber" class="java.lang.Double" isForPrompting="false">
            <defaultValueExpression><![CDATA[new Double(10000.23445)]]></defaultValueExpression>
        </parameter>
        <title>
            <band height="57" splitType="Stretch">
                <textField>
                    <reportElement x="0" y="0" width="373" height="57" uuid="2f795f8a-43fa-4b89-a173-76854a13ba48"/>
                    <textElement markup="html"/>
                    <textFieldExpression><![CDATA["Just use a textField and string concat the other text a " + java.text.NumberFormat.getNumberInstance().format($P{testNumber}) + " as you see you can even format it and remeber if you set as html you can 
    break line and <b>bold</b> text"]]></textFieldExpression> </textField> </band> </title> </jasperReport>

    Output

    Result

相关问题