This is a preview of the V5 documentation. Content may still change until the official release on August 19, 2026.
V4 V5

This page assumes unvell.ReoGrid.One is already installed (Installation).

A minimal app

using System.Windows.Forms;
using unvell.ReoGrid.Core;
using unvell.ReoGrid.Core.Style;
using unvell.ReoGrid.WinForms;

internal static class Program
{
	[STAThread]
	private static void Main()
	{
		// 高 DPI 環境では PerMonitorV2 を指定する。Windows がビットマップ拡大する代わりに
		// 物理ピクセルのクライアント領域が渡され、コントロール側が自前でスケールする。
		Application.SetHighDpiMode(HighDpiMode.PerMonitorV2);

		var grid = new ReoGridControl { Dock = DockStyle.Fill };
		BuildSheet(grid.ActiveWorksheet);

		var form = new Form { Text = "ReoGrid One", Width = 900, Height = 600 };
		form.Controls.Add(grid);
		Application.Run(form);
	}

	private static void BuildSheet(Worksheet sheet)
	{
		sheet.SetText(0, 0, "商品");
		sheet.SetText(0, 1, "単価");
		sheet.SetText(0, 2, "数量");
		sheet.SetText(0, 3, "小計");

		sheet.SetText(1, 0, "ノート");
		sheet.SetNumber(1, 1, 320);
		sheet.SetNumber(1, 2, 12);
		sheet.SetFormula(1, 3, "B2*C2");     // 先頭の '=' は付けない

		sheet.SetText(2, 0, "ボールペン");
		sheet.SetNumber(2, 1, 150);
		sheet.SetNumber(2, 2, 40);
		sheet.SetFormula(2, 3, "B3*C3");

		sheet.SetText(4, 2, "合計");
		sheet.SetFormula(4, 3, "SUM(D2:D3)");

		// 見出し行は「行のスタイル」として設定する(セルを1つずつ回さない)
		sheet.SetRowStyle(0, new StyleRecord
		{
			Bold = true,
			BackgroundColor = 0xFFEFEFEF,      // ARGB
			TextAlign = HAlign.Center,
		});

		sheet.SetNumberFormat(new RangePosition(1, 1, 4, 3), "#,##0");
	}
}

new ReoGridControl() starts out with a workbook that already contains one sheet, Sheet1. ActiveWorksheet returns that sheet.

Key points

Formulas take no leading =

sheet.SetFormula(1, 3, "B2*C2");    // 正しい
sheet.SetFormula(1, 3, "=B2*C2");   // 誤り

SetFormula parses the formula, registers its dependencies, and recalculates that cell and every cell that depends on it. Call sheet.Recalculate() only when you want to recompute the whole sheet after a bulk load.

Colors are uint ARGB values

Colors are uint, not System.Drawing.Color. This keeps the core independent of System.Drawing; opaque colors start with 0xFF.

BackgroundColor = 0xFFEFEFEF,   // 不透明のライトグレー
Color = 0xFFCC0000,             // 不透明の赤(文字色)

Use row and column styles

To format a header row or an entire column, use SetRowStyle / SetColumnStyle instead of iterating over the cells. Styles are inherited in the order cell ◁ row ◁ column ◁ sheet, so setting the style once on the row is enough. Iterating over the cells of a sheet with a million rows makes the amount of work proportional to the sheet dimensions.

Styles are immutable records

StyleRecord is a record. To change only part of an existing style, use a with expression.

var current = sheet.GetCellStyle(1, 0) ?? StyleRecord.Default;
sheet.SetCellStyle(1, 0, current with { Bold = true });

Reading values

var text = sheet.GetDisplayText(4, 3);        // 書式適用後の表示文字列
var raw = sheet.GetObjectValue(4, 3);         // double / string / bool / DateTime
var cell = sheet.GetValue(4, 3);              // CellValue(構造体・boxing なし)

Writing through cell references

Cell(...) takes an A1-style address and returns a lightweight cursor. Calls can be chained.

sheet.Cell("B2").SetNumber(320);
sheet.Cell("D2").SetFormula("B2*C2");
sheet.Cell("A1").SetText("商品").SetStyle(new StyleRecord { Bold = true });

Main control operations

OperationMembers
Selection / active cellSelection, ActiveCell, SelectionChanged
Undo / redoUndo(), Redo(), CanUndo, CanRedo (Ctrl+Z / Ctrl+Y are wired up)
ZoomZoom (0.1–4.0), ZoomChanged. Ctrl+wheel also works
Freeze panesSetFreeze(rows, cols)
Formatting the selectionToggleSelectionBold(), SetSelectionBackColor(...), SetSelectionNumberFormat(...) and more
Inserting / deleting rows and columnsInsertRowsAtSelection(), DeleteSelectedRows() and others
Auto-fitting column widthsAutoFitSelectedColumns(), AutoFitSelectedRows()
Replacing the workbookLoadWorkbook(workbook), NewWorkbook(), LoadJson(json)
Was this article helpful?