FlexReport for WinForms
クロス集計レポートの作成
データのグループ化 > クロス集計レポートの作成

クロス集計レポートは、データを 2 次元(下方向と横方向)にグループ化します。クロス集計レポートは、情報を相互参照する形式で大量のデータをまとめる場合に便利です。

次の手順に従って、「FlexReport クイックスタート」で作成したレポートにクロス集計レポートを作成します。

  1. FlexReport クイックスタートプロジェクトの Form に、Button を追加します。
  2. ボタンの Name を「crossC1Button」に、Text を「View Cross Tab-Report」に設定します。
  3. Click イベントを crossC1Button_Click という名前で作成します。
  4. 次のコードを記述します。
    Private grp2 As Group
    Private Sub crossC1Button_Click(sender As Object, e As EventArgs)
        btnEmployees.PerformClick()
        c1FlexReport1.Sections.Detail.Visible = False
        grp2 = c1FlexReport1.Groups.Add("GrpCountry", "Country", SortEnum.Ascending)
        ' 新しいグループのヘッダーセクションを書式設定します       
        c1FlexReport1.Sections.PageHeader.Height = 600
        shpfld2.Top = 600
        s = grp2.SectionHeader
        s.Height = 400
        s.AutoHeight = AutoSizeBehavior.GrowAndShrink
        s.Visible = True
        textFld4.Text = "Country"
        textFld4.Width = 1000
        textFld4.Align = FieldAlignEnum.CenterMiddle
        textFld4.Height = 400
        textFld4.Font.Bold = True
        textFld4.Font.Size = 10
        textFld5.Text = "Total"
        textFld5.Width = 1000
        textFld5.Left = 1000
        textFld5.Align = FieldAlignEnum.CenterMiddle
        textFld5.Height = 400
        textFld5.Font.Bold = True
        textFld5.Font.Size = 10
        textFld6.Text = "Sales Representative"
        textFld6.Width = 2000
        textFld6.Left = 2000
        textFld6.Align = FieldAlignEnum.CenterMiddle
        textFld6.Height = 500
        textFld6.Font.Bold = True
        textFld6.Font.Size = 10
        textFld7.Text = "Vice President"
        textFld7.Width = 1500
        textFld7.Left = 4000
        textFld7.Align = FieldAlignEnum.CenterMiddle
        textFld7.Height = 400
        textFld7.Font.Bold = True
        textFld7.Font.Size = 10
        textFld8.Text = "Sales Manager"
        textFld8.Width = 1500
        textFld8.Left = 5800
        textFld8.Align = FieldAlignEnum.CenterMiddle
        textFld8.Height = 400
        textFld8.Font.Bold = True
        textFld8.Font.Size = 10
        Dim isc As New TextField()
        isc.Text = "Inside Sales Coordinator"
        isc.Width = 1500
        isc.Left = 7500
        isc.Align = FieldAlignEnum.CenterMiddle
        isc.Height = 400
        isc.Font.Bold = True
        isc.Font.Size = 10
        isc.Visible = True
        c1FlexReport1.Sections.PageHeader.Fields.Add(isc)
        Dim f1 As New Field()
        f1.Name = "Country"
        f1.Text = "Country"
        f1.Left = 80
        f1.Top = 0
        f1.Width = 1000
        f1.Height = 400
        f1.Align = FieldAlignEnum.CenterMiddle
        f1.MarginLeft = 100
        f1.Calculated = True
        f1.Visible = True
        f1.BackColor = Color.Transparent
        f1.Font.Bold = True
        f1.Font.Size = 10
        s.Fields.Add(f1)
        Dim f7 As New TextField()
        f7.Name = "RunCount"
        f7.Text = "=Count(Title)"
        f7.Left = 1080
        f7.Top = 0
        f7.Width = 1000
        f7.Height = 400
        f7.Align = FieldAlignEnum.CenterMiddle
        f7.MarginLeft = 100
        f7.Visible = True
        f7.Font.Bold = True
        f7.Font.Size = 10
        s.Fields.Add(f7)
        Dim f8 As New TextField()
        f8.Name = "SRCount"
        f8.Text = "=Count(Title, Title = ""Sales Representative"")"
        f8.Left = 2080
        f8.Top = 0
        f8.Width = 1000
        f8.Height = 400
        f8.Align = FieldAlignEnum.CenterMiddle
        f8.MarginLeft = 100
        f8.Visible = True
        f8.Font.Bold = True
        f8.Font.Size = 10
        s.Fields.Add(f8)
        Dim f9 As New TextField()
        f9.Name = "VPCount"
        f9.Text = "=Count(Title, Title = ""Vice President, Sales"")"
        f9.Left = 4000
        f9.Top = 0
        f9.Width = 1000
        f9.Height = 400
        f9.Align = FieldAlignEnum.CenterMiddle
        f9.MarginLeft = 100
        f9.Visible = True
        f9.Font.Bold = True
        f9.Font.Size = 10
        s.Fields.Add(f9)
        Dim f10 As New TextField()
        f10.Name = "SMCount"
        f10.Text = "=Count(Title, Title = ""Sales Manager"")"
        f10.Left = 5800
        f10.Top = 0
        f10.Width = 1000
        f10.Height = 400
        f10.Align = FieldAlignEnum.CenterMiddle
        f10.MarginLeft = 100
        f10.Visible = True
        f10.Font.Bold = True
        f10.Font.Size = 10
        s.Fields.Add(f10)
        Dim f11 As New TextField()
        f11.Name = "ISCCount"
        f11.Text = "=Count(Title, Title = ""Inside Sales Coordinator"")"
        f11.Left = 7500
        f11.Top = 0
        f11.Width = 1000
        f11.Height = 400
        f11.Align = FieldAlignEnum.CenterMiddle
        f11.MarginLeft = 100
        f11.Visible = True
        f11.Font.Bold = True
        f11.Font.Size = 10
        s.Fields.Add(f11)
        c1FlexReport1.Render()
    End Sub
    
    Group grp2;
            private void crossC1Button_Click(object sender, EventArgs e)
            {
               
        btnEmployees.PerformClick();
        c1FlexReport1.Sections.Detail.Visible = false;
              
        grp2 = c1FlexReport1.Groups.Add("GrpCountry", "Country", SortEnum.Ascending);
                // 新しいグループのヘッダーセクションを書式設定します       
        c1FlexReport1.Sections.PageHeader.Height = 600;
        shpfld2.Top = 600;
        s = grp2.SectionHeader;
        s.Height = 400;
        s.AutoHeight = AutoSizeBehavior.GrowAndShrink;
        s.Visible = true;
        textFld4.Text = "Country";
        textFld4.Width = 1000;
        textFld4.Align = FieldAlignEnum.CenterMiddle;
        textFld4.Height = 400;          
        textFld4.Font.Bold = true;
        textFld4.Font.Size = 10;
        textFld5.Text = "Total";
        textFld5.Width = 1000;
        textFld5.Left = 1000;
        textFld5.Align = FieldAlignEnum.CenterMiddle;
        textFld5.Height = 400;
        textFld5.Font.Bold = true;
        textFld5.Font.Size = 10;
        textFld6.Text = "Sales Representative";
        textFld6.Width = 2000;
        textFld6.Left = 2000;
        textFld6.Align = FieldAlignEnum.CenterMiddle;
        textFld6.Height = 500;
        textFld6.Font.Bold = true;
        textFld6.Font.Size = 10;
        textFld7.Text = "Vice President";
        textFld7.Width = 1500;
        textFld7.Left = 4000;
        textFld7.Align = FieldAlignEnum.CenterMiddle;
        textFld7.Height = 400;
        textFld7.Font.Bold = true;
        textFld7.Font.Size = 10;
        textFld8.Text = "Sales Manager";
        textFld8.Width = 1500;
        textFld8.Left = 5800;
        textFld8.Align = FieldAlignEnum.CenterMiddle;
        textFld8.Height = 400;
        textFld8.Font.Bold = true;
        textFld8.Font.Size = 10;
        TextField isc = new TextField();
         isc.Text = "Inside Sales Coordinator";
         isc.Width = 1500;
         isc.Left = 7500;
         isc.Align = FieldAlignEnum.CenterMiddle;
         isc.Height = 400;
         isc.Font.Bold = true;
         isc.Font.Size = 10;
         isc.Visible = true;
         c1FlexReport1.Sections.PageHeader.Fields.Add(isc);
         Field f1 = new Field();
         f1.Name = "Country";
         f1.Text = "Country";
         f1.Left = 80;
         f1.Top = 0;
         f1.Width = 1000;
         f1.Height = 400;
         f1.Align = FieldAlignEnum.CenterMiddle;
         f1.MarginLeft = 100;
         f1.Calculated = true;
         f1.Visible = true;
         f1.BackColor = Color.Transparent;
         f1.Font.Bold = true;
         f1.Font.Size = 10;
         s.Fields.Add(f1);
         TextField f7 = new TextField();
         f7.Name = "RunCount";           
         f7.Text = "=Count(Title)";
         f7.Left = 1080;
         f7.Top = 0;
         f7.Width = 1000;
         f7.Height = 400;
         f7.Align = FieldAlignEnum.CenterMiddle;
         f7.MarginLeft = 100;
         f7.Visible = true;
         f7.Font.Bold = true;
         f7.Font.Size = 10;
         s.Fields.Add(f7);
         TextField f8 = new TextField();
         f8.Name = "SRCount";
         f8.Text = "=Count(Title, Title = \"Sales Representative\")";
         f8.Left = 2080;
         f8.Top = 0;
         f8.Width = 1000;
         f8.Height = 400;
         f8.Align = FieldAlignEnum.CenterMiddle;
         f8.MarginLeft = 100;
         f8.Visible = true;
         f8.Font.Bold = true;
         f8.Font.Size = 10;
         s.Fields.Add(f8);
         TextField f9 = new TextField();
         f9.Name = "VPCount";
         f9.Text = "=Count(Title, Title = \"Vice President, Sales\")";
         f9.Left = 4000;
         f9.Top = 0;
         f9.Width = 1000;
         f9.Height = 400;
         f9.Align = FieldAlignEnum.CenterMiddle;
         f9.MarginLeft = 100;
         f9.Visible = true;
         f9.Font.Bold = true;
         f9.Font.Size = 10;
         s.Fields.Add(f9);
         TextField f10 = new TextField();
         f10.Name = "SMCount";
         f10.Text = "=Count(Title, Title = \"Sales Manager\")";
         f10.Left = 5800;
         f10.Top = 0;
         f10.Width = 1000;
         f10.Height = 400;
         f10.Align = FieldAlignEnum.CenterMiddle;
         f10.MarginLeft = 100;
         f10.Visible = true;
         f10.Font.Bold = true;
         f10.Font.Size = 10;
         s.Fields.Add(f10);
         TextField f11 = new TextField();
         f11.Name = "ISCCount";
         f11.Text = "=Count(Title, Title = \"Inside Sales Coordinator\")";
         f11.Left = 7500;
         f11.Top = 0;
         f11.Width = 1000;
         f11.Height = 400;
         f11.Align = FieldAlignEnum.CenterMiddle;
         f11.MarginLeft = 100;
         f11.Visible = true;
         f11.Font.Bold = true;
         f11.Font.Size = 10;
         s.Fields.Add(f11);            
         c1FlexReport1.Render();
         }
    
  5. プロジェクトを実行します。[View Cross Tab-Report]ボタンをクリックしてクロス集計レポートを表示します。2 か国の従業員の役職の内訳が表示されることを確認します。