BIRT開發心得

來源:互聯網
上載者:User

Birt 小結

一、報表範本設計環境

1.使用如下URL下載報表的設計環境:

http://download.eclipse.org/birt/downloads/

       下載birt-report-framework-2.1.2.zip檔案,解壓縮該檔案到eclipse安裝目錄下。

      

       2.使用如下URL下載 itext-1.3.jar:

http://prdownloads.sourceforge.net/itext/itext-1.3.jar

3.複製itext-1.3.jar到eclipse/plugins/com.lowagie.itext_*/lib目錄下

二、報表的運行環境

1.  在http://download.eclipse.org/birt/downloads/ 中下載運行環境:birt-runtime-2.1.2.zip

解壓縮birt-runtime-2.1.2.zip,複製birt-runtime-2_1_2/ReportEngine/lib下的所有檔案到WEB應用中WEB-INF/lib/目錄下,將下載好的itext-1.3.jar也複製到該目錄下。

    2.使用Report API運行報表要設定EngineHome,代碼如下:

EngineConfig config = new EngineConfig();

config.setEngineHome( "BirtHomePath" );

其中BirtHomePath就是/birt-runtime-2_1_2/ReportEngine目錄

3.在server配置中選擇Application標籤,將WEB應用的classloader mode的值修改為:PARENT_LAST,入圖:

               

4.參考代碼片斷:

                              EngineConfig config = new EngineConfig();

                              config.setEngineHome( "E:/ReportEngine" );

                              ReportEngine engine = new ReportEngine( config );

                            if(engine==null){

                                     System.out.println("null");

}

                              IReportRunnable design=null;

                              try {

                                     design =

                                            engine.openReportDesign(

                                                   "E:/workspace/TestReport/testreport.rptdesign");

                              } catch (EngineException e) {

                                     // TODO Auto-generated catch block

                                     e.printStackTrace();

                              }

                       IRunAndRenderTask task = engine.createRunAndRenderTask(design);

                       

                              HTMLRenderOption options = new HTMLRenderOption();

                              options.setOutputFileName("c:/customers.pdf");

                              options.setOutputFormat("pdf");

                              task.setRenderOption(options);

 

                              try {

                                     task.run();

                              } catch (EngineException e1) {

                                     // TODO Auto-generated catch block

                                     e1.printStackTrace();

                              }

 

                              engine.destroy();

三、動態配置報表資料來源 

1.選擇Data Explore標籤下Data Sources選項,選擇其中需要配置的資料來源

2.選擇beforeOpen事件,輸入如下參考代碼:

importPackage( Packages.java.io );

importPackage( Packages.java.util );

fin = new java.io.FileInputStream(new String("e:/config.txt"));

props = new java.util.Properties( );

props.load(fin);

 

extensionProperties.odaURL = new String(props.getProperty("url"));

extensionProperties.odaDriverClass = new String(props.getProperty("driver"));

extensionProperties.odaUser = new String(props.getProperty("userid"));

extensionProperties.odaPassword = new String(props.getProperty("password"));

fin.close();

 

在e:/config.txt寫入資料來源配置資訊,例如:

url=jdbc:mysql://localhost:3306/test

driver=com.mysql.jdbc.Driver

userid=root

password=111111

3.以上代碼中 資料來源設定檔的路徑可以作為參數傳入。修改如下:

             fin = new java.io.FileInputStream(new String(params["propdir"]));

             在報表檔案中添加報表參數 propdir

四、向報表中傳遞參數

1.設定資料集的查詢參數(用於SQL語句的參數)

雙擊需要編輯的資料集,編寫SQL語句:如圖:

SQL語句中用。設定了查詢參數,雙擊資料集裡的Parameters選項添加參數,如圖:

添加參數面板中的Linked To Report Parameter是指資料集的查詢參數是否要和報表參數對應起來。一般選擇和定義好的報表參數對應。

2.  如果報表中定義了3個參數(pcity,ppname,propdir),如圖:

 

使用BIRT提供的API寫如下代碼:

IReportRunnable design=null;

try {

            design = engine.openReportDesign(                                            "E:/workspace/TestReport/testreport.rptdesign");

} catch (EngineException e) {

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.