V4 V5

unvell.ReoGrid.One.Wpf を導入済みであることが前提です(インストール)。

セルの読み書き・数式・スタイルの API はコア側にあるため、WinForms 版と共通です。 本ページはコントロールの配置に絞ります。値の設定方法は WinForms で始める を参照してください。

XAML に配置する

コントロールは unvell.ReoGrid.Wpf 名前空間、アセンブリは unvell.ReoGrid.One.Wpf です。

<Window x:Class="MyApp.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:rg="clr-namespace:unvell.ReoGrid.Wpf;assembly=unvell.ReoGrid.One.Wpf"
        Title="ReoGrid One" Width="900" Height="600">
  <Grid>
    <rg:ReoGridControl x:Name="grid" />
  </Grid>
</Window>

コードビハインドの InitializeComponent() の後で、grid.ActiveWorksheet に対して 値を設定します。シートを組み立てる部分は次のとおりです。

using unvell.ReoGrid.Core;
using unvell.ReoGrid.Core.Style;

internal static class SheetBuilder
{
	public static void BuildSheet(Worksheet sheet)
	{
		sheet.SetText(0, 0, "商品");
		sheet.SetText(0, 1, "単価");
		sheet.SetNumber(1, 1, 320);
		sheet.SetFormula(2, 1, "SUM(B2:B2)");

		sheet.SetRowStyle(0, new StyleRecord { Bold = true, BackgroundColor = 0xFFEFEFEF });
	}
}

MainWindow のコンストラクタから SheetBuilder.BuildSheet(grid.ActiveWorksheet) を呼びます。 セルの読み書きはコア側の API なので、ここから先は WinForms 版と全く同じです。

.csproj 側の設定:

<PropertyGroup>
  <TargetFramework>net10.0-windows</TargetFramework>
  <UseWPF>true</UseWPF>
</PropertyGroup>

WinForms 版との違い

座標系に DPI 変換が要らない

WPF の論理単位(DIP)は 96 DPI 基準であり、コアの座標系と一致します。そのため WinForms 版に あった DpiScale に相当する処理は不要で、モニターごとの DPI はフレームワークが処理します。

Panel を継承している

ReoGridControl は Panel の派生です。グリッド本体は OnRender で描画され、 スクロールバー・セルエディタ・ドロップダウンはその上に子要素として載ります。

印刷が組み込み

Print() を呼ぶと DocumentPaginator 経由で印刷ダイアログに渡ります。

using unvell.ReoGrid.Core.Printing;

grid.Print();                                   // 既定の設定で印刷
grid.Print(new PrintSettings { /* 用紙・余白・倍率など */ });

主なメンバー

WinForms 版と同名・同義です。

操作メンバー
ワークブック / アクティブシートWorkbook・ActiveWorksheet・SetWorksheet(ws)
選択範囲Selection・ActiveCell・SelectionChanged
元に戻す・やり直すUndo()・Redo()・CanUndo・CanRedo・HistoryChanged
表示倍率Zoom・ZoomChanged
ウィンドウ枠の固定SetFreeze(rows, cols)
読み込みLoadWorkbook(wb)・NewWorkbook()・LoadJson(json)
印刷Print(settings)

日本語入力

IME に対応しています。非編集状態のセルで日本語入力を開始すると、その場でエディタが開いて 入力が続きます(WinForms 版と同じ挙動)。

次に読む

ページの内容は役に立ちましたか?