Jasper reports 如何根据动态内容拉伸JasperReport中的文本字段? ##希望此字段根据内容自动拉伸## ##希望此字段根据内容自动拉伸##

Jasper reports 如何根据动态内容拉伸JasperReport中的文本字段? ##希望此字段根据内容自动拉伸## ##希望此字段根据内容自动拉伸##,jasper-reports,Jasper Reports,该字段可以通过溢出自动拉伸,但它会向下(有点像换行),而不是增加宽度。在PDF文档中,您需要注意的选项几乎没有用处 查看其他线程以了解更多信息 编辑同时检查并包括jasperreports字体扩展。也许它可以帮助实现完美的部署,而不会出现操作系统字体的问题。得到了解决方案。将所有静态文本字段和所有元素属性修改为positionType=“Float”只需将isStretchWithOverflow=“true”添加到您想要作为元素的文本字段中 <?xml version="1.0" enc

该字段可以通过溢出自动拉伸,但它会向下(有点像换行),而不是增加宽度。在PDF文档中,您需要注意的选项几乎没有用处

查看其他线程以了解更多信息


编辑同时检查并包括jasperreports字体扩展。也许它可以帮助实现完美的部署,而不会出现操作系统字体的问题。

得到了解决方案。将所有静态文本字段和所有元素属性修改为
positionType=“Float”

只需将
isStretchWithOverflow=“true”
添加到您想要作为元素的文本字段中

<?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="tree-template" pageWidth="595" pageHeight="842" columnWidth="481" leftMargin="57" rightMargin="57" topMargin="72" bottomMargin="72">
    <style name="Title" forecolor="#000000" fontName="Times New Roman" fontSize="50" isBold="false" pdfFontName="Times-Bold"/>
    <style name="SubTitle" forecolor="#666666" fontName="Times New Roman" fontSize="18" isBold="false" pdfFontName="Times-Roman"/>
    <style name="Column header" forecolor="#666666" fontName="Times New Roman" fontSize="14" isBold="true" pdfFontName="Times-Roman"/>
    <style name="Detail" mode="Transparent" fontName="Times New Roman" pdfFontName="Times-Roman"/>
    <style name="Row" mode="Transparent" fontName="Times New Roman" pdfFontName="Times-Roman">
        <conditionalStyle>
            <conditionExpression><![CDATA[$V{REPORT_COUNT}%2 == 0]]></conditionExpression>
            <style mode="Opaque" backcolor="#F0EFEF"/>
        </conditionalStyle>
    </style>
    <parameter name="JasperCustomSubReportLocation" class="net.sf.jasperreports.engine.JasperReport"/>
    <parameter name="JasperCustomSubReportDatasource" class="net.sf.jasperreports.engine.data.JRBeanCollectionDataSource"/>
    <field name="name" class="java.lang.String"/>
    <field name="notes" class="java.lang.String"/>
    <field name="state" class="java.lang.String"/>
    <field name="project" class="com.pearson.ltg.qmo.dashboard.domain.QDashProject">
        <fieldDescription><![CDATA[project]]></fieldDescription>
    </field>
    <field name="theme" class="java.lang.String"/>
    <field name="goals" class="java.lang.String"/>
    <field name="statusDetails" class="java.lang.String"/>
    <field name="mitigation" class="java.lang.String"/>
    <field name="status" class="java.lang.String"/>
    <field name="releaseDate" class="java.util.Calendar"/>
    <group name="Group1">
        <groupExpression><![CDATA[(int)($V{REPORT_COUNT}/15)]]></groupExpression>
    </group>
    <group name="Group2">
        <groupExpression><![CDATA[(int)($V{REPORT_COUNT}/5)]]></groupExpression>
        <groupHeader>
            <band height="10"/>
        </groupHeader>
    </group>
    <title>
        <band height="58" splitType="Stretch">
            <staticText>
                <reportElement style="Title" x="4" y="0" width="477" height="56"/>
                <textElement>
                    <font size="48" isBold="false"/>
                </textElement>
                <text><![CDATA[Release Details]]></text>
            </staticText>
        </band>
    </title>
    <detail>
        <band height="189" splitType="Stretch">
            <frame>
                <reportElement mode="Opaque" x="0" y="7" width="481" height="13" forecolor="#D0B48E" backcolor="#9DB1B8"/>
            </frame>
            <textField>
                <reportElement x="279" y="7" width="202" height="13"/>
                <textElement/>
                <textFieldExpression class="java.lang.String"><![CDATA[$F{name}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="79" y="7" width="100" height="13"/>
                <textElement/>
                <textFieldExpression class="java.lang.String"><![CDATA[$F{project}.getName()]]></textFieldExpression>
            </textField>
            <staticText>
                <reportElement x="2" y="7" width="79" height="13"/>
                <textElement>
                    <font isBold="true"/>
                </textElement>
                <text><![CDATA[Platform : ]]></text>
            </staticText>
            <staticText>
                <reportElement x="179" y="7" width="100" height="13"/>
                <textElement>
                    <font size="10" isBold="true" isItalic="false"/>
                </textElement>
                <text><![CDATA[Release Name :]]></text>
            </staticText>
            <staticText>
                <reportElement x="0" y="20" width="47" height="20"/>
                <textElement>
                    <font isBold="true"/>
                </textElement>
                <text><![CDATA[Status : ]]></text>
            </staticText>
            <textField>
                <reportElement x="79" y="20" width="100" height="20"/>
                <textElement/>
                <textFieldExpression class="java.lang.String"><![CDATA[$F{status}]]></textFieldExpression>
            </textField>
            <staticText>
                <reportElement x="0" y="40" width="79" height="20"/>
                <textElement>
                    <font isBold="true"/>
                </textElement>
                <text><![CDATA[Release Date: ]]></text>
            </staticText>
            <staticText>
                <reportElement x="0" y="60" width="181" height="20"/>
                <textElement>
                    <font isBold="true"/>
                </textElement>
                <text><![CDATA[Release Goals]]></text>
            </staticText>
##want this field to auto stretch as per content##
            <textField isStretchWithOverflow="true" isBlankWhenNull="true">
                <reportElement positionType="Float" stretchType="RelativeToTallestObject" x="0" y="80" width="463" height="20"/>
                <textElement>
                    <font size="10"/>
                </textElement>
                <textFieldExpression class="java.lang.String"><![CDATA[$F{goals}==null ? "Not Defined":$F{goals}]]></textFieldExpression>
            </textField>
##want this field to auto stretch as per content##
            <staticText>
                <reportElement stretchType="RelativeToTallestObject" x="0" y="100" width="98" height="20"/>
                <textElement>
                    <font isBold="true"/>
                </textElement>
                <text><![CDATA[Status Details]]></text>
            </staticText>
            <textField isStretchWithOverflow="true">
                <reportElement stretchType="RelativeToTallestObject" x="2" y="120" width="463" height="20"/>
                <textElement/>
                <textFieldExpression class="java.lang.String"><![CDATA[$F{statusDetails}==null ? "Not Defined":$F{statusDetails}]]></textFieldExpression>
            </textField>
            <staticText>
                <reportElement stretchType="RelativeToTallestObject" x="0" y="140" width="98" height="20"/>
                <textElement>
                    <font isBold="true"/>
                </textElement>
                <text><![CDATA[Risk Mitigation]]></text>
            </staticText>
            <textField>
                <reportElement stretchType="RelativeToTallestObject" x="18" y="160" width="463" height="20"/>
                <textElement/>
                <textFieldExpression class="java.lang.String"><![CDATA[$F{mitigation}==null?"Not Defined":$F{mitigation}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement stretchType="RelativeToTallestObject" x="79" y="40" width="100" height="20"/>
                <textElement/>
                <textFieldExpression class="java.lang.String"><![CDATA[new SimpleDateFormat("MMM dd,yyyy").format($F{releaseDate}.getTime())]]></textFieldExpression>
            </textField>
            <line>
                <reportElement x="0" y="180" width="481" height="1"/>
            </line>
        </band>
    </detail>
    <columnFooter>
        <band height="12" splitType="Stretch"/>
    </columnFooter>
    <pageFooter>
        <band height="13" splitType="Stretch">
            <frame>
                <reportElement mode="Opaque" x="0" y="0" width="477" height="13" forecolor="#D0B48E" backcolor="#9DB1B8"/>
                <textField pattern="EEEEE dd MMMMM yyyy">
                    <reportElement style="Column header" x="2" y="0" width="197" height="13" forecolor="#FFFFFF"/>
                    <textElement verticalAlignment="Middle">
                        <font size="10" isBold="false"/>
                    </textElement>
                    <textFieldExpression class="java.util.Date"><![CDATA[new java.util.Date()]]></textFieldExpression>
                </textField>
                <textField evaluationTime="Report">
                    <reportElement style="Column header" x="450" y="0" width="27" height="13" forecolor="#FFFFFF"/>
                    <textElement verticalAlignment="Middle">
                        <font size="10" isBold="false"/>
                    </textElement>
                    <textFieldExpression class="java.lang.String"><![CDATA[" " + $V{PAGE_NUMBER}]]></textFieldExpression>
                </textField>
                <textField>
                    <reportElement style="Column header" x="370" y="0" width="80" height="13" forecolor="#FFFFFF"/>
                    <textElement textAlignment="Right" verticalAlignment="Middle">
                        <font size="10" isBold="false"/>
                    </textElement>
                    <textFieldExpression class="java.lang.String"><![CDATA["Page "+$V{PAGE_NUMBER}+" of"]]></textFieldExpression>
                </textField>
            </frame>
        </band>
    </pageFooter>
</jasperReport>

  • 单击iReport中的特定文本字段
  • 在右侧,请参见文本字段属性
  • 选中“溢出拉伸”选项

  • 它在我的情况下起作用。

    [仅适用于Jasper Table]选择列中的文本字段,然后选择 1.位置类型:相对于顶部固定 2.拉伸类型:相对于标注栏高度 3.溢出拉伸:true 将相同内容应用于所有其他列 现在,当其中一列垂直增长时,其他字段将自动居中对齐!!

    您可以添加属性isStretchWithOverflow set为true

    如果您使用的是Jaspersoft Studio,请单击要更改的文本字段,导航到其属性,进入文本字段选项卡,然后将文本调整为
    拉伸高度
    (默认值为
    剪切文本
    )。此外,如果您的文本字段位于框架中,您应该将其位置类型设置为
    Float

    报告是如何定义的,垂直还是水平?很高兴您告诉我们发生了什么错误情况。现在,您使用的jasperreports版本是什么?你是如何编辑它的?我正在使用iReport编辑它。Jasper报表的版本为3.7.6 RTF报表中文本字段的高度未根据内容进行调整。您不应设置此选项:stretchType=“RelativeTotallesObject”。但我不认为这是问题的原因。(设置正确且充分:isStretchWithOverflow=“true”。)我正在生成一个RTF JasperReport,文本字段的高度不是自动拉伸的。找到了解决方案。将所有静态文本字段和所有元素属性修改为positionType=“Float”。很好。创建答案并检查它,以便其他人知道!此答案简单有效地解决了我的问题。这与现有答案完全相同:。除非添加新信息,否则无需重复现有答案:)请注意,从JasperReports库版本6.10开始,
    isStretchWithOverflow=“true”
    属性被
    textAdjust=“StretchHeight”
    替换。要使较新版本的Jaspersoft Studio使用old属性,可以在兼容性设置(“窗口->首选项->Jaspersoft Studio->兼容性”)中更改JasperReports库版本。
    <textField isStretchWithOverflow="true">
        <reportElement x="279" y="7" width="202" height="13"/>
        <textElement/>
        <textFieldExpression class="java.lang.String"><![CDATA[$F{name}]]></textFieldExpression>
    </textField>