ワークシートでセルコントロールの管理
セルコントロールへのアクセス
ワークシート内の既存のセルコントロールにアクセスして変更するには、開発者はControlsコレクション内のWorksheetから特定のセルコントロールにアクセスできます(セルの名前または行および列番号を使用して)。セルコントロールにアクセスしたら、開発者は実行時にそのプロパティを変更することができます。たとえば、以下の例では、ワークシートから既存のCheckBoxセルコントロールにアクセスし、そのCheckedプロパティを変更しました。
重要: Controlsコレクションには、CellControlオブジェクトとしてすべてのタイプのセルコントロールが含まれています。したがって、特定のタイプのセルコントロールにアクセスする必要がある場合は、CellControlオブジェクトをCheckBoxクラスに変換する必要があります。
// 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."); | |
} |
セルコントロールの削除
既存のセルコントロールを削除するには、開発者は単に希望のワークシートにアクセスし、Controlsコレクションからセルコントロールを指定して削除します(その名前または行&列番号を使用して)。
// 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); |