syncfusion-wpf-excel-like-grid
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseImplementing Syncfusion WPF GridControl
Syncfusion WPF GridControl 实现指南
The Syncfusion WPF GridControl is a high-performance, cell-oriented grid that functions as a
flexible tabular display engine. It makes no assumptions about data structure, supports virtual
(on-demand) data loading via , and provides Excel-like behaviors including formulas,
import/export, clipboard operations, covered cells, and 20+ built-in cell types.
QueryCellInfoSyncfusion WPF GridControl 是一款高性能、面向单元格的表格控件,可作为灵活的表格显示引擎。它不对数据结构做任何假设,支持通过实现虚拟(按需)数据加载,并提供类Excel的行为,包括公式、导入/导出、剪贴板操作、合并单元格以及20余种内置单元格类型。
QueryCellInfoWhen to Use This Skill
何时使用本技能
- Adding a GridControl to a WPF application (XAML or code-behind)
- Populating cells via direct assignment or the virtual event
QueryCellInfo - Configuring cell types (CheckBox, ComboBox, DateTimeEdit, FormulaCell, etc.)
- Customizing cell appearance (background, font, borders, data formats)
- Managing rows and columns (insert, remove, move, freeze, hide)
- Clipboard, undo/redo, and editing behavior
- Interactive features: drag-drop columns, cell drag-drop, resizing
- Formula cell support and the built-in formula library
- Exporting grid data to Excel; importing Excel workbooks into the grid
- Selection modes, events, and virtual mode patterns
- Performance tuning, virtualization, covered ranges, zooming
- Advanced features: comments, tooltips, printing, serialization, autofit
- 在WPF应用中添加GridControl(XAML或代码后置)
- 通过直接赋值或虚拟事件填充单元格
QueryCellInfo - 配置单元格类型(CheckBox、ComboBox、DateTimeEdit、FormulaCell等)
- 自定义单元格外观(背景、字体、边框、数据格式)
- 管理行和列(插入、删除、移动、冻结、隐藏)
- 剪贴板、撤销/重做以及编辑行为
- 交互功能:列拖拽、单元格拖拽、调整大小
- 公式单元格支持及内置公式库
- 将表格数据导出至Excel;将Excel工作簿导入至表格
- 选择模式、事件及虚拟模式模式
- 性能调优、虚拟化、合并区域、缩放
- 高级功能:批注、工具提示、打印、序列化、自动调整
Documentation and Navigation Guide
文档与导航指南
Getting Started
入门指南
📄 Read: references/getting-started.md
- Required assembly references
- Adding GridControl via designer or programmatically
- Setting and
RowCountColumnCount - Populating data by loop vs. virtual event
QueryCellInfo - Minimal working example
📄 阅读: references/getting-started.md
- 所需程序集引用
- 通过设计器或编程方式添加GridControl
- 设置和
RowCountColumnCount - 通过循环或虚拟事件填充数据
QueryCellInfo - 最简运行示例
Cell Types
单元格类型
📄 Read: references/cell-types.md
- 20+ built-in cell types: Header, Static, CheckBox, Button, Image, ComboBox, DropDownList, DateTimeEdit, IntegerEdit, DoubleEdit, CurrencyEdit, PercentEdit, MaskEdit, UpDownEdit, RichText, DataBoundTemplate, NestedGrid (ScrollGrid)
- Setting on individual cells or ranges
Style.CellType - ComboBox with vs.
ChoiceListItemsSource - Custom cell types (CellModel + CellRenderer pattern)
📄 阅读: references/cell-types.md
- 20余种内置单元格类型:Header、Static、CheckBox、Button、Image、ComboBox、 DropDownList、DateTimeEdit、IntegerEdit、DoubleEdit、CurrencyEdit、PercentEdit、 MaskEdit、UpDownEdit、RichText、DataBoundTemplate、NestedGrid (ScrollGrid)
- 在单个单元格或区域上设置
Style.CellType - 带与
ChoiceList的ComboBoxItemsSource - 自定义单元格类型(CellModel + CellRenderer模式)
Appearance and Styling
外观与样式
📄 Read: references/appearance-and-styling.md
- class and style inheritance hierarchy
GridStyleInfo - Volatile vs. render cell styles
- Base styles (), TableStyle, RowStyles, ColumnStyles
BaseStylesMap - Background (solid/gradient), Foreground, Font, text orientation, borders
- Numeric and DateTime format strings; interface
FormatProvider
📄 阅读: references/appearance-and-styling.md
- 类及样式继承层次
GridStyleInfo - 可变样式与渲染单元格样式
- 基础样式()、表格样式、行样式、列样式
BaseStylesMap - 背景(纯色/渐变)、前景色、字体、文本方向、边框
- 数值与DateTime格式字符串;接口
FormatProvider
Managing Rows and Columns
行与列管理
📄 Read: references/managing-rows-and-columns.md
- Setting row/column counts and default sizes
- Hiding and unhiding rows/columns ()
SetHidden - Freezing rows/columns; footer and header rows/columns
- Inserting, moving, and removing rows/columns at runtime
- Resize behavior and disabling resize controllers
📄 阅读: references/managing-rows-and-columns.md
- 设置行/列数量及默认大小
- 隐藏与取消隐藏行/列()
SetHidden - 冻结行/列;页脚与页眉行/列
- 在运行时插入、移动和删除行/列
- 调整大小行为及禁用调整大小控制器
Editing, Clipboard, and Undo/Redo
编辑、剪贴板与撤销/重做
📄 Read: references/editing-clipboard-undo.md
- flags (CopyText, CopyCellData, PasteCell, CutCell, XmlCopyPaste)
CopyPasteOption - for custom delimiters and buffer-based operations
TextDataExchange - Clipboard events and custom implementation
IGridCopyPaste - : Undo/Redo,
CommandStack,BeginTrans,CommitTransRollback - Creating derived commands for extended undo/redo
📄 阅读: references/editing-clipboard-undo.md
- 标志(CopyText、CopyCellData、PasteCell、CutCell、XmlCopyPaste)
CopyPasteOption - 用于自定义分隔符及基于缓冲区的操作
TextDataExchange - 剪贴板事件与自定义实现
IGridCopyPaste - :撤销/重做、
CommandStack、BeginTrans、CommitTransRollback - 创建派生命令以扩展撤销/重做功能
Interactive Features
交互功能
📄 Read: references/interactive-features.md
- Column drag-drop ()
AllowDragColumns - Excel-like cell drag-drop (,
AllowDragDrop)DataObjectConsumerOptions - Runtime row/column resizing and disabling resize controllers
- Hide/unhide rows and columns visually (,
HiddenBorderBrush)SetHidden
📄 阅读: references/interactive-features.md
- 列拖拽()
AllowDragColumns - 类Excel的单元格拖拽(、
AllowDragDrop)DataObjectConsumerOptions - 运行时行/列调整大小及禁用调整大小控制器
- 可视化隐藏/取消隐藏行和列(、
HiddenBorderBrush)SetHidden
Formula Cells
公式单元格
📄 Read: references/formula-cells.md
- Enabling type for individual cells or the entire grid
FormulaCell - Built-in formula library (150+ functions: Sum, Avg, Sqrt, Pow, Cos, Sin, etc.)
- Arithmetic operators and calculation precedence
- Cross-cell references (A1 notation), named ranges
- Adding custom formula functions to the library
📄 阅读: references/formula-cells.md
- 为单个单元格或整个表格启用类型
FormulaCell - 内置公式库(150余种函数:Sum、Avg、Sqrt、Pow、Cos、Sin等)
- 算术运算符与计算优先级
- 跨单元格引用(A1表示法)、命名区域
- 向库中添加自定义公式函数
Excel Import and Export
Excel导入与导出
📄 Read: references/excel-import-export.md
- Required assemblies (,
Syncfusion.XlsIO)Syncfusion.GridConverter.Wpf - Exporting entire or selected grid content to .xls / .xlsx
- Importing Excel workbooks: styles, formulas, conditional formatting, freeze panes, hyperlinks, comments
- Virtualized import for large workbooks
📄 阅读: references/excel-import-export.md
- 所需程序集(、
Syncfusion.XlsIO)Syncfusion.GridConverter.Wpf - 将整个或选定表格内容导出至.xls/.xlsx
- 导入Excel工作簿:样式、公式、条件格式、冻结窗格、 超链接、批注
- 针对大型工作簿的虚拟化导入
Selection and Events
选择与事件
📄 Read: references/selection-and-events.md
- Selection modes: cell, row, column (flags)
AllowSelection - event pattern for virtual data loading
QueryCellInfo - for view-specific overrides
PrepareRenderCell - Common grid events: ,
CommitCellInfo, clipboard events,CurrentCellActivated,RowsInserted,ColumnsMoved, etc.ResizingRows - Working with and
GridRangeInfoSelectedRanges
📄 阅读: references/selection-and-events.md
- 选择模式:单元格、行、列(标志)
AllowSelection - 用于虚拟数据加载的事件模式
QueryCellInfo - 用于视图特定重写的
PrepareRenderCell - 常见表格事件:、
CommitCellInfo、剪贴板事件、CurrentCellActivated、RowsInserted、ColumnsMoved等ResizingRows - 使用与
GridRangeInfoSelectedRanges
Performance and Virtualization
性能与虚拟化
📄 Read: references/performance-virtualization.md
- Virtual mode fundamentals and best practices
QueryCellInfo - Covered ranges () and floating cells
CoveredCells - Zooming the grid
- High-frequency update patterns
📄 阅读: references/performance-virtualization.md
- 虚拟模式基础与最佳实践
QueryCellInfo - 合并区域()与浮动单元格
CoveredCells - 表格缩放
- 高频更新模式
Advanced Features
高级功能
📄 Read: references/advanced-features.md
- Cell comments, input-message tips, and tooltips
- Cell layout customization (covered cells, merged ranges, autofit)
- Printing grid content
- Serialization: saving and loading grid state
- Autofit rows and columns to content
📄 阅读: references/advanced-features.md
- 单元格批注、输入消息提示与工具提示
- 单元格布局自定义(合并单元格、合并区域、自动调整)
- 打印表格内容
- 序列化:保存与加载表格状态
- 根据内容自动调整行和列
Quick Start Example
快速入门示例
csharp
1. Add assemblies:
Syncfusion.Grid.Wpf
Syncfusion.GridCommon.Wpf,
Syncfusion.Linq.Base,
Syncfusion.Shared.Wpf
// 2. XAML — place GridControl inside a ScrollViewer
<ScrollViewer>
<syncfusion:GridControl x:Name="gridControl" />
</ScrollViewer>
// 3. Code-behind: set size and populate
gridControl.Model.RowCount = 100;
gridControl.Model.ColumnCount = 10;
// Option A — direct assignment
for (int i = 0; i < 100; i++)
for (int j = 0; j < 10; j++)
gridControl.Model[i, j].CellValue = $"{i}/{j}";
// Option B — virtual mode (preferred for large data)
gridControl.QueryCellInfo += (s, e) =>
{
if (e.Cell.RowIndex > 0 && e.Cell.ColumnIndex > 0)
e.Style.CellValue = $"{e.Cell.RowIndex}/{e.Cell.ColumnIndex}";
};csharp
1. Add assemblies:
Syncfusion.Grid.Wpf
Syncfusion.GridCommon.Wpf,
Syncfusion.Linq.Base,
Syncfusion.Shared.Wpf
// 2. XAML — place GridControl inside a ScrollViewer
<ScrollViewer>
<syncfusion:GridControl x:Name="gridControl" />
</ScrollViewer>
// 3. Code-behind: set size and populate
gridControl.Model.RowCount = 100;
gridControl.Model.ColumnCount = 10;
// Option A — direct assignment
for (int i = 0; i < 100; i++)
for (int j = 0; j < 10; j++)
gridControl.Model[i, j].CellValue = $"{i}/{j}";
// Option B — virtual mode (preferred for large data)
gridControl.QueryCellInfo += (s, e) =>
{
if (e.Cell.RowIndex > 0 && e.Cell.ColumnIndex > 0)
e.Style.CellValue = $"{e.Cell.RowIndex}/{e.Cell.ColumnIndex}";
};Common Patterns
常见模式
Apply a Cell Type to a Range
为区域应用单元格类型
csharp
// Set an entire column to CheckBox
for (int i = 1; i <= gridControl.Model.RowCount; i++)
gridControl.Model[i, 3].CellType = "CheckBox";csharp
// Set an entire column to CheckBox
for (int i = 1; i <= gridControl.Model.RowCount; i++)
gridControl.Model[i, 3].CellType = "CheckBox";Alternate Row Colors via PrepareRenderCell
通过PrepareRenderCell实现交替行颜色
csharp
gridControl.PrepareRenderCell += (s, e) =>
{
if (e.Cell.RowIndex > 0 && e.Cell.RowIndex % 2 == 0)
e.Style.Background = Brushes.LightSkyBlue;
};csharp
gridControl.PrepareRenderCell += (s, e) =>
{
if (e.Cell.RowIndex > 0 && e.Cell.RowIndex % 2 == 0)
e.Style.Background = Brushes.LightSkyBlue;
};Freeze Header and Enable Formula Cells
冻结页眉并启用公式单元格
csharp
gridControl.Model.FrozenRows = 1;
gridControl.Model.HeaderRows = 1;
gridControl.BaseStylesMap["Standard"].StyleInfo.CellType = "FormulaCell";csharp
gridControl.Model.FrozenRows = 1;
gridControl.Model.HeaderRows = 1;
gridControl.BaseStylesMap["Standard"].StyleInfo.CellType = "FormulaCell";Export to Excel
导出至Excel
csharp
gridControl.Model.ExportToExcel(@"Output.xlsx", ExcelVersion.Excel2007);csharp
gridControl.Model.ExportToExcel(@"Output.xlsx", ExcelVersion.Excel2007);Key Style Properties
关键样式属性
| Property | Purpose |
|---|---|
| Sets built-in or custom cell type string |
| Data value stored in the cell |
| Cell background brush |
| Cell text color |
| Cell font size |
| Individual border pens (Top/Bottom/Left/Right) |
| Format string (e.g., |
| Row height in device-independent units |
| Column width |
| Number of rows frozen at top |
| Number of columns frozen at left |
undefined| Property | Purpose |
|---|---|
| 设置内置或自定义单元格类型字符串 |
| 单元格中存储的数据值 |
| 单元格背景画刷 |
| 单元格文本颜色 |
| 单元格字体大小 |
| 单独的边框画笔(上/下/左/右) |
| 格式字符串(例如 |
| 行高(设备独立单位) |
| 列宽 |
| 顶部冻结的行数 |
| 左侧冻结的列数 |
undefined