EGL レポート・ドライバー関数のサンプル・コード

以下に、 次の 3 つの異なるデータ・ソースを使用したレポートの埋め込み方法を示す、 コードの断片を示します。
  • データベース接続
  • データ・レコード
  • SQL 文からの結果セット
次のコードの断片は、 データ・ソースとしてデータベース接続を使用したレポートの埋め込み方法を示しています (SQL 文は .jasper 設計ファイルにあります)。
//変数宣言
myReport     Report;
myReportData ReportData;

//Function containing report invocation code
function makeReport()
	//Initialize Report file locations
	myReport.reportDesignFile =
		"c:¥¥workspace¥¥report_project¥¥bin¥¥report_package¥¥myReport.jasper";;
	myReport.reportDestinationFile = "c:¥¥temp¥¥myReport.jrprint";

	// 接続を介してレポート・データを取得します
	sysLib.defineDatabaseAlias("alias", "connectionName");
	sysLib.connect("alias", "userid", "password");
	myReportData.connectionName = "alias";
	myReport.reportData = myReportData;


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

	//Export the report in PDF format
	myReport.reportExportFile = "c:¥¥temp¥¥reportDesignFileName.pdf";
	reportLib.exportReport(myReport, ExportFormat.pdf);
end
次のコードの断片は、 データ・ソースとして独自の内部レコードを使用したレポートの埋め込み方法を示しています。 最初に、次のようなレコードをプログラム外部で定義することが必要です。
Record myRecord type BasicRecord
	author String;
	description String;
	title String;
end
次に、レポートを埋め込み、駆動する関数を作成します。
// 変数宣言
myReport     Report;
myReportData ReportData;

recArray        myRecord[];
recArrayElement myRecord;

//Function containing the report driving code
function makeReport()
	//Initialize report file locations
	myReport.reportDesignFile =
		"c:¥¥workspace¥¥report_project¥¥bin¥¥report_package¥¥myReport.jasper";;
	myReport.reportDestinationFile = "c:¥¥temp¥¥myReport.jrprint";

	// レポート・データを取得します
	populateReportData();
	myReport.reportData = myReportData;

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

	//Export the report in HTML format
	myReport.reportExportFile = "c:¥¥temp¥¥myReport.html";
	reportLib.exportReport(myReport, ExportFormat.html);
end

function populateReportData()
	recArrayElement.author="Jane Austen";
	recArrayElement.title="Northanger Abbey";
	recArrayElement.description = "British Novel";
	recArray.appendElement(recArrayElement);

	recArrayElement.author = "Jane Austen";
	recArrayElement.title="Emma";
	recArrayElement.description = "British Novel";
	recArray.appendElement(recArrayElement);

	recArrayElement.author = "Charles Dickens";
	recArrayElement.title="Our Mutual Friend";
	recArrayElement.description = "British Novel";
	recArray.appendElement(recArrayElement);

	recArrayElement.author = "Gustave Flaubert";
	recArrayElement.title="Madame Bovary";
	recArrayElement.description = "French Novel";
	recArray.appendElement(recArrayElement);

	recArrayElement.author = "M. Lermontov";
	recArrayElement.title="Hero of Our Time";
	recArrayElement.description = "Russian Novel";
	recArray.appendElement(recArrayElement);
end
次のコードの断片は、 データ・ソースとして SQL 文を使用したレポートの埋め込み方法を示しています。 この例は、ご使用のプログラム・プロパティー・ファイル内のデフォルトのデータベース接続を前提としています。
//変数宣言
myReport     Report;
myReportData ReportData;

//Function containing report driving code
function makeReport()
//Initialize Report file locations
	myReport.reportDesignFile =
		"c:¥¥workspace¥¥report_project¥¥bin¥¥report_package¥¥myReport.jasper";;
	myReport.reportDestinationFile = "c:¥¥temp¥¥myReport.jrprint";

	// SQL ステートメントを介してレポート・データを取得します
	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 = "c:¥¥temp¥¥myReport.txt";
	reportLib.exportReport(myReport, ExportFormat.text);
end
フィードバック
(C) Copyright IBM Corporation 2000, 2005. All Rights Reserved.