【问题标题】:New lines in server generated report text field but not in iReport服务器生成的报告文本字段中的新行,但 iReport 中没有
【发布时间】:2012-04-12 04:37:06
【问题描述】:

我在iReport 中有一个表格,可以正确生成 PDF:

<componentElement>
    <reportElement key="server vendor table" style="table" x="272" y="437" width="150" height="115"/>
    <jr:table>
        <jr:column width="50">
            <jr:columnHeader style="table_CH" height="15" rowSpan="1">
                <staticText>
                    <reportElement x="5" y="0" width="45" height="15"/>
                    <textElement/>
                    <text><![CDATA[Server Vendor]]></text>
                </staticText>
            </jr:columnHeader>
            <jr:detailCell style="table_TD" height="18" rowSpan="1">
                <textField>
                    <reportElement x="5" y="0" width="45" height="15"/>
                    <textElement/>
                    <textFieldExpression><![CDATA[$F{vendor}]]></textFieldExpression>
                </textField>
            </jr:detailCell>
        </jr:column>
        <jr:column width="50">
            <jr:columnHeader style="table_CH" height="15" rowSpan="1">
                <staticText>
                    <reportElement x="5" y="0" width="45" height="15"/>
                    <textElement/>
                    <text><![CDATA[# Hosts]]></text>
                </staticText>
            </jr:columnHeader>
            <jr:detailCell style="table_TD" height="18" rowSpan="1">
                <textField>
                    <reportElement x="5" y="0" width="45" height="15"/>
                    <textElement/>
                    <textFieldExpression><![CDATA[$F{count}]]></textFieldExpression>
                </textField>
            </jr:detailCell>
        </jr:column>
        <jr:column width="50">
            <jr:columnHeader style="table_CH" height="15" rowSpan="1">
                <staticText>
                    <reportElement x="5" y="0" width="45" height="15"/>
                    <textElement/>
                    <text><![CDATA[Host %]]></text>
                </staticText>
            </jr:columnHeader>
            <jr:detailCell style="table_TD" height="18" rowSpan="1">
                <textField>
                    <reportElement x="5" y="0" width="45" height="15"/>
                    <textElement/>
                    <textFieldExpression><![CDATA[$F{pc}]]></textFieldExpression>
                </textField>
            </jr:detailCell>
        </jr:column>
    </jr:table>
</componentElement>

iReport生成报告时,正确生成PDF,结果为:

但是当使用 Java 生成时,第一列中“HP”的文本条目被分成多行:

请注意,只有“HP”文本被分割 - 较长的文本(例如“Dell inc.”)被分割。

我猜我需要设置一些属性,但我看不出我需要设置哪个属性。

Class.forName("org.postgresql.Driver");
Connection conn = DriverManager.getConnection("jdbc:postgresql://localhost:5432/hardwaredata","???","???");       
InputStream input = new FileInputStream(new File("/reports/hardware_report.jrxml"));
JasperDesign design = JRXmlLoader.load(input);
input.close();
Map<String, Object> param_map = new HashMap<String, Object>();
JasperReport jReport = JasperCompileManager.compileReport(design);
JasperPrint jPrint = JasperFillManager.fillReport(jReport, param_map, conn);
String path = application.getRealPath("/") + "/"+"static_report.pdf";
JasperExportManager.exportReportToPdfFile(jPrint, path);

【问题讨论】:

    标签: jasper-reports ireport


    【解决方案1】:

    我以前见过这个。我不记得找到真正的原因。同样奇怪(但很高兴)我发现像“HP”这样的字符串不会表现出这种行为。

    尝试更改您的文本字段以显示:$F{Vendor} + " "

    一定要记录一个错误!但这可能足以解决眼前的问题。

    【讨论】:

    • 非常感谢 mdahlman!这解决了这个问题——有点小技巧,但至少它是正确的。按照建议,我会针对 jasperreports 提出一个错误!
    【解决方案2】:

    在垂直对齐的文本的属性中,勾选标题为“Stretch with overflow”的字段

    【讨论】:

    • 这不起作用 - 字段没有溢出;有足够的宽度可以容纳字符。设置此值对“HP”字符串没有影响 - 但可以看出它对其他一些条目有影响(使它们成为双线),因此我确实设置了正确。
    • 嗯,它为什么要这样做真是太奇怪了。
    猜你喜欢
    • 2014-01-20
    • 1970-01-01
    • 2015-02-20
    • 1970-01-01
    • 2012-06-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多