GrapeCity ActiveReports for .NET 16.0J
ページの挿入または追加
ActiveReportsユーザーガイド > 基本操作 > セクションレポートの基本操作 > 共通操作 > ページの挿入または追加

セクションレポートでは、複数のレポートを実行したり、ページコレクションの全体または特定の部分をマージして1つのレポートとして表示することができます。マージされたレポートを含むドキュメントは、RDFファイルへの保存やエクスポートも可能です。

次の手順は、Windowsフォーム上にViewerコントロールを配置し、Visual Studioのプロジェクトに2つのセクションレポート(コード)のテンプレート(rptOneおよびrptTwo)を追加したことを前提にしています。それぞれの詳細については、「クイックスタート」および「Viewerの使用」を参照してください。

他のレポートからページを追加する

次のサンプルコードでは、ページコレクションを反復処理し、レポート全体を他のレポートに追加します。PagesCollectionのAddメソッドでvalue引数を使用し、レポートドキュメントのページを参照することができます。

  1. Viewerコントロールが配置されているFormのデザインビューで、タイトルバーをダブルクリックし、Form_Loadイベントのイベント処理メソッドを使用します。
  2. ハンドラに次のコードを記載し、rptOneにrptTwoのページコレクションを追加します。

    Visual Basic

    Visual Basicコード(Form_Loadイベント内に貼り付けます)
    コードのコピー
    Dim i As Integer
    Dim rpt As New rptOne()
    rpt.Run()
    Dim rpt2 As New rptTwo()
    rpt2.Run()
    For i = 0 To rpt2.Document.Pages.Count - 1
         rpt.Document.Pages.Add(rpt2.Document.Pages(i))
    Next
    Viewer1.Document = rpt.Document
                                                            
    

    C#

    C#コード(Form_Loadイベント内に貼り付けます)
    コードのコピー
    int i;
    rptOne rpt1 = new rptOne();
    rpt1.Run();
    rptTwo rpt2 = new rptTwo();
    rpt2.Run();
    for(i = 0; i < rpt2.Document.Pages.Count; i++)
    {
    rpt1.Document.Pages.Add(rpt2.Document.Pages[i]);
    }
    viewer1.Document = rpt1.Document;
                                                  
    

指定したページの範囲をレポートに追加する

レポートの指定したページを他のレポートに追加するには、AddRangeメソッドを使用します。このメソッドの2つのオーバーロードで引数を設定できます。オーバーロードでページオブジェクトの配列を設定し、レポートの指定したページの範囲を別のレポートに追加できます。

  1. Viewerコントロールが配置されているフォームのデザインビューで、フォームのタイトルバーをダブルクリックし、Form_Loadイベントのイベント処理メソッドを使用します。
  2. AddRange()メソッドを使用し、rptTwoからrptOneに指定したページを追加するには、ハンドラに次のコードを記載します。

    Visual Basic

    Visual Basicコード(Form_Loadイベント内に貼り付けます)
    コードのコピー
    Dim rpt1 As New rptOne()
    rpt1.Run()
    Dim rpt2 As New rptTwo()
    rpt2.Run()
    rpt1.Document.Pages.AddRange(New GrapeCity.ActiveReports.Document.Section.Page() {rpt2.Document.Pages(1), rpt2.Document.Pages(2)})
    Viewer1.Document = rpt1.Document
                                            
    

    C#

    C#コード(Form_Loadイベント内に貼り付けます)
    コードのコピー
    rptOne rpt1 = new rptOne();
    rpt1.Run();
    rptTwo rpt2 = new rptTwo(); 
    rpt2.Run();
    rpt1.Document.Pages.AddRange(new GrapeCity.ActiveReports.Document.Section.Page[] {rpt2.Document.Pages[0],rpt2.Document.Pages[1]} );
    viewer1.Document = rpt1.Document;
    

レポートにページを挿入する

レポートにページを挿入するには、2つの引数を指定したInsertメソッドを使用できます。indexで対象レポートに挿入するページの位置を指定し、valueで挿入するレポートのページを参照します。

  1. Viewerコントロールが配置されているフォームのデザインビューで、フォームのタイトルバーをダブルクリックし、Form_Loadイベントのイベント処理メソッドを使用します。
  2. rptTwoの1ページをrptOneの先頭に挿入するには、ハンドラに次のコードを記載します。

    Visual Basic

    Visual Basicコード(Form_Loadイベント内に貼り付けます)
    コードのコピー
    Dim rpt1 As New rptOne()
    rpt1.Run()
    Dim rpt2 As New rptTwo()
    rpt2.Run()
    rpt1.Document.Pages.Insert(0, rpt2.Document.Pages(0))
    Viewer1.Document = rpt1.Document
                                                            
    

    C#

    C#コード(Form_Loadイベント内に貼り付けます)
    コードのコピー
    rptOne rpt1 = new rptOne();
    rpt1.Run();
    rptTwo rpt2 = new rptTwo();
    rpt2.Run();
    rpt1.Document.Pages.Insert(0, rpt2.Document.Pages[0]);
    viewer1.Document = rpt1.Document;
                                                            
    

レポートの指定した位置に新規ページを挿入する

レポートの指定した位置に新規ページを挿入するには、InsertNewメソッドを使用できます。indexで指定したページの後で新規ページを挿入します。

  1. Viewerコントロールが配置されているフォームのデザインビューで、フォームのタイトルバーをダブルクリックし、Form_Loadイベントのイベント処理メソッドを使用します。
  2. rptOneの先頭に新規のページを挿入するには、ハンドラに次のコードを記載します。

    Visual Basic

    Visual Basicコード(Form_Loadイベント内に貼り付けます)
    コードのコピー
    Dim rpt1 As New rptOne()
    rpt1.Run()
    rpt1.Document.Pages.InsertNew(0)
    
    rpt1.Document.Pages(0).Width = rpt1.Document.Pages(1).Width
    rpt1.Document.Pages(0).Height = rpt1.Document.Pages(1).Height
    rpt1.Document.Pages(0).Orientation = rpt1.Document.Pages(1).Orientation Viewer1.Document = rpt1.Document

    C#

    C#コード(Form_Loadイベント内に貼り付けます)
    コードのコピー
    rptOne rpt1 = new rptOne();
    rpt1.Run();
    rpt1.Document.Pages.InsertNew(0);
    rpt1.Document.Pages(0).Width = rpt1.Document.Pages(1).Width;
    rpt1.Document.Pages(0).Height = rpt1.Document.Pages(1).Height;
    rpt1.Document.Pages(0).Orientation = rpt1.Document.Pages(1).Orientation;
    viewer1.Document = rpt1.Document; 
    
    メモ: InsertNewメソッドで追加されるページは既定値(Letterサイズ)となるため、サイズと印刷向きを明示的に指定する必要があります。