バージョン

バンド

Band エレメントは、大小任意のレポートのシナリオを処理できる基本機能と高度な機能の両方を持つ標準のコンテンツ セクションです。Band エレメントに追加できるレイアウト エレメントの完全なリストについては、 「レイアウト エレメント比較表」を参照してください。

Band エレメントは、繰り返し可能なヘッダ、フッタ、デバイダを持つことができる点で固有です。これらのヘッダとフッタはページではなくバンドを修飾します。したがって、ヘッダとフッタはバンドのコンテンツの上下に表示されます。いくつかの追加設定を設定するだけでなく、任意の数のパターン コンテンツを挿入することも可能です。

以下のコンテンツ レイアウト セクションは、Band エレメント固有です。

  • Header – Header エレメントは、新しいページで始まるたびにコンテンツ領域の上部を修飾します。この機能を利用するためには、 IBand  オブジェクトの Header プロパティを新しい IBandHeader オブジェクトに設定します。もちろん、ヘッダが不要な場合には、このプロパティを設定する必要はありません。

  • Divider Divider エレメントは、最後のページを除く全ページのフッタの前の、コンテンツ領域の下部に表示します。これにより Divider エレメントはセクションが次ページに続くことを識別するために最適なエレメントとなっています。この機能を利用するためには、IBand オブジェクトの Divider プロパティを新しい IBandDivider オブジェクトに設定します。Header と同様に、Divider を使用したくない場合にはこのプロパティを設定する必要はありません。

  • Footer – Footer エレメントはコンテンツ領域の下部を修飾します。Band がページの下部までいかないうちに終了すると、フッタはページではなく、バンドの終わりに表示します。ただし、バンドがページ全体を占めるようにしたい場合には(最後のページだけでなく各ページに適用)、Band オブジェクトの Stretch プロパティを True に設定してください。

Band.png

バンドがひとつの PDF ファイルを作成

以下の手順はヘッダ、デバイダ、フッタが付いた単一のバンドを含む PDF ファイルを作成するプロセスを説明します。

達成すること

この詳細なガイドのコードによって、このトピックの上部にあるスクリーンショットと非常に似た PDF レポートを作成することができます。後はレポートをパブリッシュするだけです。レポートのパブリッシュについての詳細は、 「レポートをパブリッシュ」を参照してください。

次の手順を実行します

  1. レポートを作成しセクションを追加します。

作成する各レポートは Report オブジェクトとして開始します。いったんインスタンス化されたら、AddSection メソッドによって必要なだけセクションを Report オブジェクトに追加できます。メインの Report にひとつだけセクションを追加することができます。セクションが作成されたら、その他すべてのタイプのコンテンツを追加できます。以下のコードはレポートを作成し、セクションを追加して、そのセクションのためのいくつかのページ固有のプロパティを設定します。

Visual Basic の場合:

'
' レポートを作成しセクションを追加します。
'
Dim report As Infragistics.Documents.Reports.Reports.Report.Report = _
  New Infragistics.Documents.Reports.Reports.Report.Report()
Dim section1 As Infragistics.Documents.Reports.Reports.Report.Section.ISection = _
  report.AddSection()
section1.PagePaddings = _
  New Infragistics.Documents.Reports.Reports.Report.Paddings(50)

C# の場合:

//
// レポートを作成しセクションを追加します。
//
Infragistics.Documents.Reports.Reports.Report.Report report =
  new Infragistics.Documents.Reports.Reports.Report.Report();
Infragistics.Documents.Reports.Reports.Report.Section.ISection section1 =
  report.AddSection();
section1.PagePaddings =
  new Infragistics.Documents.Reports.Reports.Report.Paddings(50);
  1. バンドをセクションに追加します。

メインのセクションへのバンドまたは任意のコンテンツ セクションの追加は、メソッドを呼び出すことによって実行されます。この場合、Section オブジェクトの AddBand メソッドを呼び出します。AddBand はセクションから作成された新しい IBand オブジェクトへの参照を返します。したがって、新しい IBand オブジェクトにその参照を割り当てる必要があります。以下のコードは新しい IBand オブジェクトを作成し、その Background をグレーに設定します。

Visual Basic の場合:

'
' バンドをセクションに追加します。
'
Dim band As Infragistics.Documents.Reports.Reports.Report.Band.IBand = _
  section1.AddBand()
band.Background = _
  New Infragistics.Documents.Reports.Reports.Report.Background _
  (Infragistics.Documents.Reports.Reports.Graphics.Colors.LightGray)

C# の場合:

//
// バンドをセクションに追加します。
//
Infragistics.Documents.Reports.Reports.Report.Band.IBand band =
  section1.AddBand();
band.Background =
  new Infragistics.Documents.Reports.Reports.Report.Background
  (Infragistics.Documents.Reports.Reports.Graphics.Colors.LightGray);
  1. ヘッダをバンドに追加します。

メソッドの呼び出しに関連したセクションにバンドを追加することと、ヘッダをハンドに追加することは若干異なります。バンドのヘッダ、デバイダ、フッタはすでに存在しているので、これらへの参照を取得するだけです。新しいヘッダを作成して、Band オブジェクトの Header プロパティに設定します。この参照を取得したら、プロパティを修正できます。以下のコードはバンドのヘッダを取得して、いくつかのレイアウトおよび視覚的プロパティを設定し、コンテンツをヘッダに追加します。

Visual Basic の場合:

'
' ヘッダをバンドに追加します。
'
' バンドのヘッダへの参照を取得して
' bandHeader オブジェクトに割り当てます。
Dim bandHeader As Infragistics.Documents.Reports.Reports.Report.Band.IBandHeader = _
  band.Header
' 全ページでヘッダを繰り返すことになります。
bandHeader.Repeat = True
' ヘッダの高さは、ページの高さの 5% に
' なります。
bandHeader.Height = _
  New Infragistics.Documents.Reports.Reports.Report.FixedHeight(30)
' ヘッダの背景色は明るい青色になります。
bandHeader.Background = _
  New Infragistics.Documents.Reports.Reports.Report.Background _
  (Infragistics.Documents.Reports.Reports.Graphics.Colors.SteelBlue)
' ヘッダの水平および垂直の配置を設定します。
bandHeader.Alignment = _
  New Infragistics.Documents.Reports.Reports.Report.ContentAlignment _
  ( _
    Infragistics.Documents.Reports.Reports.Report.Alignment.Left, _
    Infragistics.Documents.Reports.Reports.Report.Alignment.Middle _
  )
' バンドの下側の境界線は
' 濃い青色の実線になります。
bandHeader.Borders.Bottom = _
  New Infragistics.Documents.Reports.Reports.Report.Border _
  (Infragistics.Documents.Reports.Reports.Graphics.Pens.DarkBlue)
' 左端と右端の周囲に 5 ピクセルのパディングを追加します。
bandHeader.Paddings.Horizontal = 5
' テキストのコンテンツをヘッダに追加します。
Dim bandHeaderText As Infragistics.Documents.Reports.Reports.Report.Text.IText = _
  bandHeader.AddText()
bandHeaderText.AddContent("IBandHeader")

C# の場合:

//
// ヘッダをバンドに追加します。
//
// バンドのヘッダへの参照を取得して
// bandHeader オブジェクトに割り当てます。
Infragistics.Documents.Reports.Reports.Report.Band.IBandHeader bandHeader =
  band.Header;
// 全ページでヘッダを繰り返すことになります。
bandHeader.Repeat = true;
// ヘッダの高さは、ページの高さの 5% に
// なります。
bandHeader.Height =
  new Infragistics.Documents.Reports.Reports.Report.FixedHeight(30);
// ヘッダの背景色は明るい青色になります。
bandHeader.Background =
  new Infragistics.Documents.Reports.Reports.Report.Background
  (Infragistics.Documents.Reports.Reports.Graphics.Colors.SteelBlue);
// ヘッダの水平および垂直の配置を設定します。
bandHeader.Alignment =
  new Infragistics.Documents.Reports.Reports.Report.ContentAlignment
  (
    Infragistics.Documents.Reports.Reports.Report.Alignment.Left,
    Infragistics.Documents.Reports.Reports.Report.Alignment.Middle
  );
// バンドの下側の境界線は
// 濃い青色の実線になります。
bandHeader.Borders.Bottom =
  new Infragistics.Documents.Reports.Reports.Report.Border
  (Infragistics.Documents.Reports.Reports.Graphics.Pens.DarkBlue);
// 左端と右端の周囲に 5 ピクセルのパディングを追加します。
bandHeader.Paddings.Horizontal = 5;
// テキストのコンテンツをヘッダに追加します。
Infragistics.Documents.Reports.Reports.Report.Text.IText bandHeaderText =
  bandHeader.AddText();
bandHeaderText.AddContent("IBandHeader");
  1. バンドのデバイダを追加します。

デバイダは、複数の目的のために使用できます。デバイダはフッタの前のページの終わりに表示するため、デバイダを使用してバンドが次ページに続くことを示す、または一種のページ番号システムとして使用して、実際のバンドが何ページあるのかを識別することができます(ページのメイン フッタに含まれる任意のページ番号デバイスに加えて)。バンドのヘッダから参照を取得しなければならなかったのと全く同じように、デバイダに同じことを実行する必要があります。以下のコードは、標準のプロパティを修正しコンテンツを追加するだけでなく、この作業を実行します。

Visual Basic の場合:

'
' バンドのデバイダを追加します。
'
' バンドのデバイダへの参照を取得します。
Dim bandDivider As Infragistics.Documents.Reports.Reports.Report.Band.IBandDivider = _
  band.Divider
' ページの高さの 5% に高さを設定します。
bandDivider.Height = _
  New Infragistics.Documents.Reports.Reports.Report.FixedHeight(30)
' デバイダの中央にコンテンツを配置します。
bandDivider.Alignment = _
  New Infragistics.Documents.Reports.Reports.Report.ContentAlignment _
  (Infragistics.Documents.Reports.Reports.Report.Alignment.Middle)
' テキストをデバイダに追加して、ページでセンタリングします。
Dim bandDividerText As Infragistics.Documents.Reports.Reports.Report.Text.IText = _
  bandDivider.AddText()
bandDividerText.AddContent("Band Continued...")
bandDividerText.Alignment = _
  New Infragistics.Documents.Reports.Reports.Report.TextAlignment _
  (Infragistics.Documents.Reports.Reports.Report.Alignment.Center)

C# の場合:

//
// バンドのデバイダを追加します。
//
// バンドのデバイダへの参照を取得します。
Infragistics.Documents.Reports.Reports.Report.Band.IBandDivider bandDivider =
  band.Divider;
// ページの高さの 5% に高さを設定します。
bandDivider.Height =
  new Infragistics.Documents.Reports.Reports.Report.FixedHeight(30);
// デバイダの中央にコンテンツを配置します。
bandDivider.Alignment =
  new Infragistics.Documents.Reports.Reports.Report.ContentAlignment
  (Infragistics.Documents.Reports.Reports.Report.Alignment.Middle);
// テキストをデバイダに追加して、ページでセンタリングします。
Infragistics.Documents.Reports.Reports.Report.Text.IText bandDividerText =
  bandDivider.AddText();
bandDividerText.AddContent("Band Continued...");
bandDividerText.Alignment =
  new Infragistics.Documents.Reports.Reports.Report.TextAlignment
  (Infragistics.Documents.Reports.Reports.Report.Alignment.Center);
  1. バンドのフッタを追加します。

バンドのフッタは、ページの下部にある点を除き、ヘッダと同じように動作します。ヘッダと同じように、フッタは全ページに表示するか、最終ページのみに表示するかのいずれかを選択できます。

Visual Basic の場合:

'
' バンドのフッタを追加します。
'
' バンドのフッタへの参照を取得します。
Dim bandFooter As Infragistics.Documents.Reports.Reports.Report.Band.IBandFooter = _
  band.Footer
' バンドは全ページで繰り返しません。
' 最後のページのみに表示されます。
bandFooter.Repeat = False
' フッタの背景色は明るい青色になります。
bandFooter.Background = _
  New Infragistics.Documents.Reports.Reports.Report.Background _
  (Infragistics.Documents.Reports.Reports.Graphics.Colors.LightSteelBlue)
' フッタの高さはページの高さの 5% になります。
bandFooter.Height = _
  New Infragistics.Documents.Reports.Reports.Report.FixedHeight(30)
' フッタのコンテンツを水平および垂直に配置します。
bandFooter.Alignment = _
  New Infragistics.Documents.Reports.Reports.Report.ContentAlignment _
  ( _
    Infragistics.Documents.Reports.Reports.Report.Alignment.Left, _
    Infragistics.Documents.Reports.Reports.Report.Alignment.Middle _
  )
' フッタの上側の境界線は
' 濃い青色の実線になります。
bandFooter.Borders.Top = _
  New Infragistics.Documents.Reports.Reports.Report.Border _
  (Infragistics.Documents.Reports.Reports.Graphics.Pens.DarkBlue)
' 左右に 5 ピクセルのパディングを追加します。
bandFooter.Paddings.Horizontal = 5
' テキストのコンテンツをフッタに追加します。
Dim bandFooterText As Infragistics.Documents.Reports.Reports.Report.Text.IText = _
  bandFooter.AddText()
bandFooterText.AddContent("IBandFooter")

C# の場合:

//
// バンドのフッタを追加します。
//
// バンドのフッタへの参照を取得します。
Infragistics.Documents.Reports.Reports.Report.Band.IBandFooter bandFooter =
  band.Footer;
// バンドは全ページで繰り返しません。
// 最後のページのみに表示されます。
bandFooter.Repeat = false;
// フッタの背景色は明るい青色になります。
bandFooter.Background =
  new Infragistics.Documents.Reports.Reports.Report.Background
  (Infragistics.Documents.Reports.Reports.Graphics.Colors.LightSteelBlue);
// フッタの高さはページの高さの 5% になります。
bandFooter.Height =
  new Infragistics.Documents.Reports.Reports.Report.FixedHeight(30);
// フッタのコンテンツを水平および垂直に配置します。
bandFooter.Alignment =
  new Infragistics.Documents.Reports.Reports.Report.ContentAlignment
  (
    Infragistics.Documents.Reports.Reports.Report.Alignment.Left,
    Infragistics.Documents.Reports.Reports.Report.Alignment.Middle
  );
// フッタの上側の境界線は
// 濃い青色の実線になります。
bandFooter.Borders.Top =
  new Infragistics.Documents.Reports.Reports.Report.Border
  (Infragistics.Documents.Reports.Reports.Graphics.Pens.DarkBlue);
// 左右に 5 ピクセルのパディングを追加します。
bandFooter.Paddings.Horizontal = 5;
// テキストのコンテンツをフッタに追加します。
Infragistics.Documents.Reports.Reports.Report.Text.IText bandFooterText =
  bandFooter.AddText();
bandFooterText.AddContent("IBandFooter");
  1. コンテンツをバンドに追加します。

これでヘッダ、デバイダ、フッタが設定されたので、バンドの実際のコンテンツを追加する必要があります。バンドに追加しなければならないのがシンプルなテキストだけの場合、Band オブジェクトの AddText メソッドを使用するだけで十分です。この例では、以下のサンプル テキストを使用します。

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec imperdiet mattis sem. Nunc ornare elit at justo. In quam nulla, lobortis non, commodo eu, eleifend in, elit. Nulla eleifend. Nulla convallis. Sed eleifend auctor purus. Donec velit diam, congue quis, eleifend et, pretium id, tortor. Nulla semper condimentum justo. Etiam interdum odio ut ligula. Vivamus egestas scelerisque est. Donec accumsan. In est urna, vehicula non, nonummy sed, malesuada nec, purus. Vestibulum erat. Vivamus lacus enim, rhoncus nec, ornare sed, scelerisque varius, felis. Nam eu libero vel massa lobortis accumsan. Vivamus id orci. Sed sed lacus sit amet nibh pretium sollicitudin. Morbi urna.

新しい文字列を作成して、コンテンツを上記のテキストに設定します。これで、FOR ループを伴ったより複雑なシナリオに関係したときにコードをより簡単に読むことができるようになります。新しい IText オブジェクトを作成しますが、まだ設定しないでください。FOR ループで IText オブジェクトを設定します。このようにループによって、繰り返しのたびに新しいオブジェクトを作成するのではなく同じオブジェクトを再利用し続けます。FOR ループは同じテキストのパラグラフを 20 回作成して、バンドに完全なボディを提供します。

Visual Basic の場合:

'
' コンテンツをバンドに追加します。
'
Dim string1 As String = "Lorem ipsum..."
Dim bandText As Infragistics.Documents.Reports.Reports.Report.Text.IText
For i As Integer = 0 To 19
  bandText = band.AddText()
  bandText.AddContent(string1)
  bandText.Paddings.All = 5
Next i

C# の場合:

//
// コンテンツをバンドに追加します。
//
string string1 = "Lorem ipsum...";
Infragistics.Documents.Reports.Reports.Report.Text.IText bandText;
for (int i = 0; i < 20; i++)
{
  bandText = band.AddText();
  bandText.AddContent(string1);
  bandText.Paddings.All = 5;
}