1
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Jasper Report 簡易帳票出力 (Java 実装)

Posted at

JasperReport出力(Java側)

はじめに

JasperReportsは、Jaspersoft Studioで帳票テンプレートを作成後、テンプレートファイルを読み込んで帳票出力を行う。
デザイナーツールの使い方は多いが、デザイナーで作成したファイルを実装に組み込む方法が少なかったため、忘備で記載する。

構成

  • DataSourceのセット(デザイナーで作成したxml ファイルをセットするイメージ)
  • 帳票出力マネージャーの実行

データソース

※ データソースごとに利用するクラスが異なる。

CSV

	JRDataSource data = new JRCsvDataSource(inputPath);
	// 1行目はヘッダーとみなす
	((JRCsvDataSource) data).setUseFirstRowAsHeader(true);

帳票出力

※ 出力ファイルごとに実行メソッドが異なる

PDF


// parametersはMap<String, Object> 型			JasperRunManager.runReportToPdfFile(this.templatefilePath, this.outputFilePath, this.parameters,
					this.dataSource);

Excel

			// Excel フォーマットの変換
			JRXlsxExporter xlsxExporter = new JRXlsxExporter();

			// 読み込みデータ
			xlsxExporter.setExporterInput(new SimpleExporterInput(
					JasperFillManager.fillReport(this.templatefilePath, this.parameters, this.dataSource)));
			// 出力先を決定
			xlsxExporter.setExporterOutput(new SimpleOutputStreamExporterOutput(this.outputFilePath));

			// Excel フォーマット設定はなし
			xlsxExporter.exportReport();

※ xlsの場合はJRXlsExporterを利用する。

1
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?