2

iReportPDFを正しく生成するテーブルがあります。

<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が正しく生成され、結果は次のようになります。 iReportを使用して生成された正しい結果

ただし、Javaを使用して生成された場合、最初の列の「HP」のテキストエントリは複数の行に分割されます。 Javaコードを使用して生成された間違った結果

「HP」テキストのみが分割されることに注意してください。スペースが含まれる長いテキスト(「Dellinc。」など)は分割されません。

いくつかのプロパティを設定する必要があると思いますが、どのプロパティを設定する必要があるのか​​わかりません。

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);
4

2 に答える 2

0

垂直方向に配置されているテキストのプロパティで、[オーバーフローを伴うストレッチ]というタイトルのフィールドにチェックマークを付けます

于 2012-04-11T14:23:22.463 に答える
0

私はこれを前に見たことがあります。本当の原因を見つけたのを覚えていません。同様に奇妙なことに(しかし幸いにも)、「HP」のような文字列はこの動作を示さないことがわかりました。

これを表示するには、テキストフィールドを変更してみてください。$F{Vendor} + " "

バグも必ず記録してください。しかし、それは差し迫った問題を解決するのに十分かもしれません。

于 2012-04-11T20:37:06.463 に答える