Hantera Cell Kontroller i arbetsblad

Åtkomst till Cell kontroller

För att komma åt och ändra en befintlig cellkontroll i kalkylbladet kan utvecklare komma åt en specifik cellkontroll frånKontroller samling avArbetsblad genom att ange cellen (med cellnamn eller dess plats i termer av rad- och kolumnnummer) där cellkontrollen visas. När en cellkontroll väl har nåtts kan utvecklare ändra dess egenskaper under körning. Till exempel, i exemplet nedan, har vi kommit åt en befintligKryssruta cellstyrning frånArbetsblad och ändrade dess kontrollerade egenskap.

VIKTIG: Kontroller samling innehåller alla typer av cellkontroller i form avCellControl föremål. Så, om du behöver komma åt en specifik typ av cellkontroll, sägKryssruta då måste du typcastaCellControl protestera motKryssruta klass.

// 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.");
}

Ta bort Cell kontroller

För att ta bort en befintlig cellkontroll kan utvecklare helt enkelt komma åt ett önskat kalkylblad och sedanTa bort cellkontrollen frånKontroller samling avArbetsblad genom att ange cellen (med dess namn eller rad- och kolumnnummer) som innehåller cellkontroll.

// 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);