SPREAD for WPF 3.0J - GcSpreadSheet
数式バーの追加
SPREAD for WPF 3.0J - GcSpreadSheet > 開発者ガイド > 数式と関数 > 数式バーの追加

GcSpreadSheetコンポーネントとともに数式バーを追加でき、さまざまな数式や関数を操作することができます。GcFormulaBarを使用するには、「クイックスタート」の手順を実行して両方のコンポーネントを連結します。

GcFormulaBarコンポーネントの操作

MainWindow.xaml.csファイルを開き、Loadedイベントのハンドラーに次のサンプルコードを追加します。

コードのコピー
private void Window_Loaded(object sender, RoutedEventArgs e)
{
    gcSpreadSheet.Workbook.ActiveSheet.Cells["A1"].Text = "First Name";
    gcSpreadSheet.Workbook.ActiveSheet.Cells["A2"].Text = "Charles";
    gcSpreadSheet.Workbook.ActiveSheet.Cells["A3"].Text = "Rachel";
    gcSpreadSheet.Workbook.ActiveSheet.Cells["A4"].Text = "Steve";
    gcSpreadSheet.Workbook.ActiveSheet.Cells["A5"].Text = "Jennifer";
    gcSpreadSheet.Workbook.ActiveSheet.Cells["A6"].Text = "Charles";

    gcSpreadSheet.Workbook.ActiveSheet.Cells["B1"].Text = "Sales";
    gcSpreadSheet.Workbook.ActiveSheet.Cells["B2"].Value = 23900;
    gcSpreadSheet.Workbook.ActiveSheet.Cells["B3"].Value = 11002;
    gcSpreadSheet.Workbook.ActiveSheet.Cells["B4"].Value = 3222;
    gcSpreadSheet.Workbook.ActiveSheet.Cells["B5"].Value = 9191;
    gcSpreadSheet.Workbook.ActiveSheet.Cells["B6"].Value = 4523;

    gcSpreadSheet.Workbook.ActiveSheet.Cells["C1"].Text = "Countries";
    gcSpreadSheet.Workbook.ActiveSheet.Cells["C2"].Text = "UK";
    gcSpreadSheet.Workbook.ActiveSheet.Cells["C3"].Text = "UK";
    gcSpreadSheet.Workbook.ActiveSheet.Cells["C4"].Text = "USA";
    gcSpreadSheet.Workbook.ActiveSheet.Cells["C5"].Text = "USA";
    gcSpreadSheet.Workbook.ActiveSheet.Cells["C6"].Text = "USA";

    gcSpreadSheet.Workbook.ActiveSheet.Cells["D1"].Text = "Quarter";
    gcSpreadSheet.Workbook.ActiveSheet.Cells["D2"].Text = "Qtr1";
    gcSpreadSheet.Workbook.ActiveSheet.Cells["D3"].Text = "Qtr2";
    gcSpreadSheet.Workbook.ActiveSheet.Cells["D4"].Text = "Qtr3";
    gcSpreadSheet.Workbook.ActiveSheet.Cells["D5"].Text = "Qtr1";
    gcSpreadSheet.Workbook.ActiveSheet.Cells["D6"].Text = "Qtr2";

    gcSpreadSheet.Workbook.ActiveSheet.Cells["B8"].Text = "Total Sales:";
    gcSpreadSheet.Workbook.ActiveSheet.Cells["C8"].Formula = "SUM(B2:B6)";
    gcSpreadSheet.Workbook.ActiveSheet.Cells["C8"].Activate();
    gcSpreadSheet.Workbook.ActiveSheet.Columns[0, 4].ColumnWidth = 80;        
}
コードのコピー
Private Sub Window_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs)
    gcSpreadSheet.Workbook.ActiveSheet.Cells("A1").Text = "First Name"
    gcSpreadSheet.Workbook.ActiveSheet.Cells("A2").Text = "Charles"
    gcSpreadSheet.Workbook.ActiveSheet.Cells("A3").Text = "Rachel"
    gcSpreadSheet.Workbook.ActiveSheet.Cells("A4").Text = "Steve"
    gcSpreadSheet.Workbook.ActiveSheet.Cells("A5").Text = "Jennifer"
    gcSpreadSheet.Workbook.ActiveSheet.Cells("A6").Text = "Charles"
    gcSpreadSheet.Workbook.ActiveSheet.Cells("B1").Text = "Sales"
    gcSpreadSheet.Workbook.ActiveSheet.Cells("B2").Value = 23900
    gcSpreadSheet.Workbook.ActiveSheet.Cells("B3").Value = 11002
    gcSpreadSheet.Workbook.ActiveSheet.Cells("B4").Value = 3222
    gcSpreadSheet.Workbook.ActiveSheet.Cells("B5").Value = 9191
    gcSpreadSheet.Workbook.ActiveSheet.Cells("B6").Value = 4523
    gcSpreadSheet.Workbook.ActiveSheet.Cells("C1").Text = "Countries"
    gcSpreadSheet.Workbook.ActiveSheet.Cells("C2").Text = "UK"
    gcSpreadSheet.Workbook.ActiveSheet.Cells("C3").Text = "UK"
    gcSpreadSheet.Workbook.ActiveSheet.Cells("C4").Text = "USA"
    gcSpreadSheet.Workbook.ActiveSheet.Cells("C5").Text = "USA"
    gcSpreadSheet.Workbook.ActiveSheet.Cells("C6").Text = "USA"
    gcSpreadSheet.Workbook.ActiveSheet.Cells("D1").Text = "Quarter"
    gcSpreadSheet.Workbook.ActiveSheet.Cells("D2").Text = "Qtr1"
    gcSpreadSheet.Workbook.ActiveSheet.Cells("D3").Text = "Qtr2"
    gcSpreadSheet.Workbook.ActiveSheet.Cells("D4").Text = "Qtr3"
    gcSpreadSheet.Workbook.ActiveSheet.Cells("D5").Text = "Qtr1"
    gcSpreadSheet.Workbook.ActiveSheet.Cells("D6").Text = "Qtr2"
    gcSpreadSheet.Workbook.ActiveSheet.Cells("B8").Text = "Total Sales:"
    gcSpreadSheet.Workbook.ActiveSheet.Cells("C8").Formula = "SUM(B2:B6)"
    gcSpreadSheet.Workbook.ActiveSheet.Cells("C8").Activate()
    gcSpreadSheet.Workbook.ActiveSheet.Columns(0, 4).ColumnWidth = 80
End Sub

アプリケーションを実行してGcSpreadSheetとともにアプリケーションにGcFormulaBarコンポーネントが追加されていることを確認します。セル範囲B2:B6に適用されている数式が数式バーで表示されます。