管理工作表中的 Cell 控件
Contents
[
Hide
]
本主题讨论有关使用 Aspose.Cells.GridDesktop 的 API 管理单元格控件的一些重要概念。我们将解释开发人员如何从他们的工作表中访问、修改和删除单元格控件。让我们来看看它。
访问 Cell 控件
要访问和修改工作表中现有的单元格控件,开发人员可以从控件的集合工作表通过指定显示单元格控件的单元格(使用单元格名称或其在行号和列号方面的位置)。访问单元格控件后,开发人员可以在运行时修改其属性。例如,在下面给出的示例中,我们访问了一个现有的复选框细胞控制从工作表并修改了它的 Checked 属性。
重要的: 控件集合包含所有类型的单元格控件,形式为细胞控制对象。所以,如果你需要访问特定类型的单元格控件,比如说复选框那么你将不得不强制转换细胞控制反对复选框班级。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// Accessing the worksheet of the Grid that is currently active | |
Worksheet sheet = gridDesktop1.GetActiveWorksheet(); | |
// Getting the location of the cell that is currently in focus | |
CellLocation cl = sheet.GetFocusedCellLocation(); | |
// Accessing cell control and typecasting it to CheckBox | |
Aspose.Cells.GridDesktop.CheckBox cb = (Aspose.Cells.GridDesktop.CheckBox)sheet.Controls[cl.Row, cl.Column]; | |
if (cb != null) | |
{ | |
// Modifying the Checked property of CheckBox | |
cb.Checked = true; | |
} | |
else | |
{ | |
MessageBox.Show("Please add control before accessing it."); | |
} |
删除 Cell 控件
要删除现有的单元格控件,开发人员可以简单地访问所需的工作表,然后去掉从细胞控制控件的集合工作表通过指定包含单元格控件的单元格(使用其名称或行号和列号)。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// Accessing the worksheet of the Grid that is currently active | |
Worksheet sheet = gridDesktop1.GetActiveWorksheet(); | |
// Getting the location of the cell that is currently in focus | |
CellLocation cl = sheet.GetFocusedCellLocation(); | |
// Removing the cell control by specifying the location of cell containing it | |
sheet.Controls.Remove(cl.Row, cl.Column); |