Lägg till ActiveX-kontroller med Aspose.Cells
Contents
[
Hide
]
Du kan lägga till ActiveX-kontroller med Aspose.Cells med hjälp avShapeCollection.AddActiveXControl() metod. Denna metod tar en parameterControlTypesom talar om vilken typ av ActiveX-kontroll som måste läggas till i ett kalkylblad. Den har följande värden.
- ControlType.CheckBox
- ControlType.ComboBox
- ControlType.CommandButton
- ControlType.Image
- ControlType.Label
- ControlType.ListBox
- ControlType.RadioButton
- ControlType.ScrollBar
- ControlType.SpinButton
- ControlType.TextBox
- ControlType.ToggleButton
- ControlType.Okänd
När du väl har lagt till ActiveX-kontrollen i formsamlingen kan du komma åt ActiveX-kontrollobjektet viaShape.ActiveXControl egenskap och ställ sedan in dess olika egenskaper.
Följande exempelkod lägger till Toggle Button ActiveX Control med Aspose.Cells.
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create workbook object | |
Workbook wb = new Workbook(); | |
// Access first worksheet | |
Worksheet sheet = wb.Worksheets[0]; | |
// Add Toggle Button ActiveX Control inside the Shape Collection | |
Shape s = sheet.Shapes.AddActiveXControl(ControlType.ToggleButton, 4, 0, 4, 0, 100, 30); | |
// Access the ActiveX control object and set its linked cell property | |
ActiveXControl c = s.ActiveXControl; | |
c.LinkedCell = "A1"; | |
// Save the worbook in xlsx format | |
wb.Save(dataDir + "AddActiveXControls_out.xlsx", SaveFormat.Xlsx); |