ReoGrid 提供两种机制来控制工作表行为:WorksheetSettings(基于标志的开关设置)和 WorksheetOptions(基于值的配置)。
WorksheetSettings
方法
var sheet = reoGridControl.CurrentWorksheet;
// 启用设置
sheet.EnableSettings(WorksheetSettings.Edit_Readonly);
// 禁用设置
sheet.DisableSettings(WorksheetSettings.Edit_Readonly);
// 使用显式布尔值设置
sheet.SetSettings(WorksheetSettings.Edit_Readonly, true);
// 检查设置是否已启用
bool isReadonly = sheet.HasSettings(WorksheetSettings.Edit_Readonly);
事件
sheet.SettingsChanged += (s, e) =>
{
Console.WriteLine("Settings changed");
};
行为设置
| 设置 | 说明 |
|---|
Behavior_DoubleClickToFitRowHeight | 允许双击自动适应行高 |
Behavior_DoubleClickToFitColumnWidth | 允许双击自动适应列宽 |
Behavior_MouseWheelToScroll | 允许使用鼠标滚轮滚动 |
Behavior_MouseWheelToZoom | 允许使用 Ctrl + 鼠标滚轮缩放 |
Behavior_ShortcutKeyToZoom | 允许使用 Ctrl+加号 / Ctrl+减号缩放 |
Behavior_DragToMoveCells | 允许通过拖动移动或复制选区 |
Behavior_DragToMoveColumnHeader | 允许通过拖动标题移动列(保留) |
Behavior_ScrollToFocusCell | 始终滚动以保持焦点单元格可见 |
Behavior_AllowUserChangingPageBreaks | 允许用户使用鼠标调整分页符 |
编辑设置
| 设置 | 说明 |
|---|
Edit_Readonly | 使工作表只读 |
Edit_AutoFormatCell | 用户输入后自动格式化数据 |
Edit_FriendlyPercentInput | 在百分比格式单元格输入时显示 % 符号 |
Edit_AutoAdjustRowHeight | 当字体大小增加时自动调整行高 |
Edit_AllowAdjustRowHeight | 允许用户拖动调整行高 |
Edit_AllowAdjustColumnWidth | 允许用户拖动调整列宽 |
Edit_DragSelectionToMoveCells | 允许拖放移动单元格内容 |
Edit_DragSelectionToFillSerial | 允许拖动自动填充 |
外观设置
| 设置 | 说明 |
|---|
View_ShowColumnHeader | 显示列标题 |
View_ShowRowHeader | 显示行标题 |
View_ShowHorizontalRuler | 显示水平标尺(保留) |
View_ShowVerticalRuler | 显示垂直标尺(保留) |
View_ShowGuideLine | 显示网格线 |
View_ShowHiddenCellLine | 显示隐藏行/列的指示线 |
View_AllowShowRowOutlines | 显示行大纲面板 |
View_AllowShowColumnOutlines | 显示列大纲面板 |
View_ShowPageBreaks | 显示分页线 |
View_AllowCellTextOverflow | 允许单元格文本溢出到相邻单元格 |
View_ShowPrintAreasEnable | 显示打印区域边界 |
公式设置
| 设置 | 说明 |
|---|
Formula_AutoUpdateReferenceCell | 行/列变化时自动更新公式引用 |
Formula_AutoPickingAddress | 在公式编辑期间允许选取单元格地址 |
Formula_AutoFormat | 自动纠正和格式化公式 |
WorksheetOptions
Options 属性提供基于值的额外配置设置:
var options = sheet.Options;
公式计算选项
| 属性 | 类型 | 默认值 | 说明 |
|---|
FormulaCalculationTiming | enum | Auto | 公式计算时机(Auto、OnDemand 等) |
FormulaCalculationPrecision | enum | Double | 公式计算精度 |
选区选项
| 属性 | 类型 | 默认值 | 说明 |
|---|
AlwaysMoveSelectionToUnlockedCell | bool | false | 工作表锁定时自动将选区移到未锁定的单元格 |
AllowSelectCellWhenHitDropdownCell | bool | true | 点击下拉单元格时允许选择单元格 |
滚动条选项
| 属性 | 类型 | 默认值 | 说明 |
|---|
AutoHideHorizontalScrollBar | bool | false | 不需要时自动隐藏水平滚动条 |
AutoHideVerticalScrollBar | bool | false | 不需要时自动隐藏垂直滚动条 |
异步处理选项
这些选项控制大型工作表的异步单元格处理:
| 属性 | 类型 | 默认值 | 说明 |
|---|
AutoSuspendProcessesForFasterDataLoading | bool | false | 批量数据加载期间暂停处理以提高性能 |
AllowAsyncProcess | bool | false | 启用异步单元格处理 |
AsyncProcessDelay | int | — | 异步处理开始前的延迟(毫秒) |
AsyncProcessIntervalTime | int | — | 异步处理批次之间的间隔(毫秒) |
AsyncProcessBatchSize | int | — | 每批处理的单元格数量 |
示例:大数据量配置
var options = sheet.Options;
// 启用异步处理以提高大数据集的性能
options.AllowAsyncProcess = true;
options.AsyncProcessBatchSize = 1000;
options.AsyncProcessIntervalTime = 50;
// 批量加载期间暂停处理
options.AutoSuspendProcessesForFasterDataLoading = true;
复制和克隆选项
// 从另一个工作表复制选项
sheet.Options.CopyFrom(otherSheet.Options);
// 为新工作表克隆选项
var newOptions = sheet.Options.Clone(newSheet);
常见配置模式
只读工作表
sheet.SetSettings(WorksheetSettings.Edit_Readonly, true);
隐藏所有界面元素
sheet.SetSettings(WorksheetSettings.View_ShowRowHeader, false);
sheet.SetSettings(WorksheetSettings.View_ShowColumnHeader, false);
sheet.SetSettings(WorksheetSettings.View_ShowGuideLine, false);
禁用用户调整大小
sheet.SetSettings(WorksheetSettings.Edit_AllowAdjustRowHeight, false);
sheet.SetSettings(WorksheetSettings.Edit_AllowAdjustColumnWidth, false);
sheet.SetSettings(WorksheetSettings.Behavior_DoubleClickToFitRowHeight, false);
sheet.SetSettings(WorksheetSettings.Behavior_DoubleClickToFitColumnWidth, false);
优化批量数据加载
sheet.Options.AutoSuspendProcessesForFasterDataLoading = true;
sheet.SuspendConditionalStyleUpdate = true;
// 加载数据...
sheet.SuspendConditionalStyleUpdate = false;
sheet.ApplyAllConditionalStyles();
相关主题