EGL 报告驱动程序函数的样本代码

此主题包含一些代码段,它们将显示如何使用三个不同数据源生成报告:
  • 数据库连接
  • 数据记录
  • SQL 语句
以下代码段显示如何通过将数据库连接用作数据源来生成报告:
//Variable declaration
myReport     Report;
myReportData ReportData;

//Function containing report invocation code
 function makeReport()			
       //Initialize Report file locations
	     myReport.reportDesignFile = "reportDesignFileName.jasper";
	     myReport.reportDestinationFile = 
 "reportDestinationFileName.jrprint";

       //Set the report data via a connection using the SQL statement 
       //embedded in the report design 
	     sysLib.defineDatabaseAlias("alias", "databaseName");
       sysLib.connect("alias", "userid", "password");
	     myReportData.connectionName="connectionName";
       myReport.reportData = myReportData;


       //Fill the report with data
       reportLib.fillReport(myReport, DataSource.databaseConnection);
       //Export the report in PDF format
	     myReport.reportExportFile = "reportDesignFileName.pdf";
	     reportLib.exportReport(myReport, ExportFormat.pdf);
  end
    
以下代码段显示如何通过将报告数据灵活记录用作数据源来生成报告:
//Variable declaration
myReport     Report;
myReportData ReportData;

//Function containing the report driving code
function makeReport()
	   //Initialize myReport file locations
	   myReport.reportDesignFile = "reportDesignFileName.jasper";
     myReport.reportDestinationFile = 
 "reportDestinationFileName.jrprint";

         //Set the report data 
	       populateReportData();
	       myReport.reportData = myReportData;

        //Fill the report with data
	      reportLib.fillReport(myReport, DataSource.reportData);

        //Export the report in HTML format
	      myReport.reportExportFile = "reportDesignFileName.html";
	      reportLib.exportReport(myReport, ExportFormat.html);
end
    
function populateReportData()
	  //Insert EGL code here which populates myReportData
    ...
end
    
以下代码段显示如何通过将 SQL 语句用作数据源来生成报告:
//Variable declaration	
myReport     Report;
myReportData ReportData;

//Function containing report driving code
function makeReport()
    	//Initialize Report file locations
	  myReport.reportDesignFile = "reportDesignFileName.jasper";
	  myReport.reportDestinationFile = "reportDestinationFileName.jrprint";

    //Set the report data via a SQL statement
	  myReportData.sqlStatement = "SELECT * FROM dataBaseTable";
	  myReport.reportData = myReportData;

    //Fill the report with data
	  reportLib.fillReport(myReport, DataSource.sqlStatement);

    //Export the report in text format
	  myReport.reportExportFile = "reportOutputFileName.txt";
	  reportLib.exportReport(myReport, ExportFormat.text);
end
    
使用条款 | 反馈
(C) Copyright IBM Corporation 2000, 2005. All Rights Reserved.