ActiveReportsでは、Printメソッドを使用してレポート(ページレポート、RDLレポート、またはセクションレポート)を印刷します。
Printメソッドには、以下のいずれかの方法でアクセスできます。
以下のサンプルコードでは、各Printメソッドの使用方法を説明します。
Viewer.Printメソッドを使用する
標準の印刷方法です。ViewerクラスのPrintメソッドを使用し、Viewerコントロール上にあるレポートを印刷します。印刷処理を実行する前に、レポートが完全にロードされていることを確認してください。
Visual Basic
| Visual Basicコード(ViewerのLoadCompletedイベント内に張り付けます) |
コードのコピー
|
|---|---|
| Viewer1.Print(True, True, True) | |
C#
| C#コード(ViewerのLoadCompletedイベント内に張り付けます) |
コードのコピー
|
|---|---|
| viewer1.Print(true, true, true); | |
SectionDocumentクラスまたはPageDocumentクラスから、Printメソッドを使用する
SectionDocumentクラスまたはPageDocumentクラスから、Printメソッドを使用します。
セクションレポート
Visual Basic
| Visual Basicコード(コードビューの先頭に張り付けます) |
コードのコピー
|
|---|---|
| Imports GrapeCity.ActiveReports | |
| Visual Basicコード(Form_Loadイベント内に張り付けます) |
コードのコピー
|
|---|---|
| Dim rpt = New SectionReport1() rpt.Run(False) Dim sectionDocument As Document.SectionDocument = rpt.Document sectionDocument.Print(True, True, False) |
|
C#
| C#コード(コードビューの先頭に張り付けます) |
コードのコピー
|
|---|---|
| using GrapeCity.ActiveReports; | |
| C#コード(Form_Loadイベント内に張り付けます) |
コードのコピー
|
|---|---|
| var rpt = new SectionReport1(); rpt.Run(false); GrapeCity.ActiveReports.Document.SectionDocument sectionDocument = rpt.Document; sectionDocument.Print(true, true, false); |
|
ページレポート
Visual Basic
| Visual Basicコード(コードビューの先頭に張り付けます) |
コードのコピー
|
|---|---|
| Imports GrapeCity.ActiveReports | |
| Visual Basic(Form_Loadイベント内に張り付けます) |
コードのコピー
|
|---|---|
| Dim file_name As String = "..\..\PageReport1.rdlx" Dim pageReport As New GrapeCity.ActiveReports.PageReport(New System.IO.FileInfo(file_name)) Dim pageDocument As New GrapeCity.ActiveReports.Document.PageDocument(pageReport) pageDocument.Print(True, True, False) |
|
C#
| C#コード(コードビューの先頭に張り付けます) |
コードのコピー
|
|---|---|
| using GrapeCity.ActiveReports; | |
| C#コード(Form_Loadイベント内に張り付けます) |
コードのコピー
|
|---|---|
| string file_name = @"..\..\PageReport1.rdlx"; GrapeCity.ActiveReports.PageReport pageReport = new GrapeCity.ActiveReports.PageReport(new System.IO.FileInfo(file_name)); GrapeCity.ActiveReports.Document.PageDocument pageDocument = new GrapeCity.ActiveReports.Document.PageDocument(pageReport); pageDocument.Print(true, true, false); |
|
メモ: このPrintメソッドは、GrapeCity.ActiveReports.Viewer.CommonアセンブリのGrapeCity.ActiveReports名前空間にあるPrintExtension.Printメソッドの拡張メソッドとして実装されています。
そのため、SectionDocumentクラスまたはPageDocumentクラスからPrintメソッドにアクセスするには、プロジェクトにGrapeCity.ActiveReports.Viewer.Commonへの参照を追加する必要があります。また、上記サンプルコードのように、Imports(Visual Basic .NET)または、using(C#)ステートメントを使用してGrapeCity.ActiveReports名前空間を参照する必要があります。