簡體   English   中英

在Jasper報表中查找資源包屬性

[英]Locating Resource Bundle Property in Jasper Reports

我編寫了一個小型Java程序來練習Jasper Reports

下面是我的Java程序,它將生成報告並導出為PDF。

public class BaseReporter {
    public static void main(String[] args)  {

        try { 
        InputStream inputStream = BaseReporter.class.getResourceAsStream("/reports/helloworld.jasper");

        DataBeanMaker dataBeanMaker = new DataBeanMaker();
        ArrayList<DataBean> dataBeanList = dataBeanMaker.addDataBean();

        JRBeanCollectionDataSource JRbeancollectiondatasource = new JRBeanCollectionDataSource(dataBeanList);

        Map<String, Object> parameters = new HashMap<String, Object>();
        parameters.put("Created By", "xxx");
        parameters.put("StylePath", "d:/Learn-WS/Jasper/src/reports/jr.jrtx");


        // Export to PDF
        JasperPrint jasperPrint = JasperFillManager.fillReport(inputStream, parameters, JRbeancollectiondatasource);
        JasperExportManager.exportReportToPdfFile(jasperPrint, "d:/Learn-WS/Jasper/src/reports/helloworld.pdf");

       System.out.println("report process completed ....");
        }
        catch(Exception e) {
            System.out.println(e.getMessage());
        }
    }
}

我的包裝結構是

project
       src
          com
             BaseReport.java
             DataBean.java
             DataBeanMaker.java
          reports
             helloworld.jasper
             helloworld.jrxml
             jr.jrtx
          jr.properties

jr.properties文件中,我添加了要在報告中使用的屬性。 report.name =“測試報告”

我已經將我的資源包名稱包含在jasperReport標記中的helloworld.jrxml文件中,其屬性名為resourceBundle =“ jr”

我在報表中將資源包屬性稱為

<title>
        <band height="30">
            <staticText>
                <reportElement uuid="6fbe7eb7-04cd-4c03-bc6e-b2cda3026d3b" mode="Opaque" x="0" y="3" width="535" height="23"/>
                <textElement textAlignment="Center">
                    <font size="14" isBold="true"/>
                </textElement>
                <text><![CDATA[$R{report.name}]]></text>
            </staticText>
        </band>
    </title>

但是資源束屬性未在報表中正確加載/放置。

請幫助我,並在此先感謝。

我在報表文件中找到了用於資源包的解決方案 在報告文件*的.jrxml文件,必須使用與父標簽文本框,而不是標簽文本標簽textFieldExpression和它工作得很好。

<title>
        <band height="30">
            <textField>
                <reportElement uuid="ec4f36de-cf2b-4575-a585-3e860ad8faec" mode="Opaque" x="199" y="0" width="125" height="20" forecolor="#0000FF"/>
                <textElement textAlignment="Center">
                    <font size="10"/>
                </textElement>
                <textFieldExpression><![CDATA[$R{report.name}]]></textFieldExpression>
            </textField>
        </band>
    </title>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM