Aggiungi controlli ActiveX usando Aspose.Cells
Puoi aggiungere controlli ActiveX con Aspose.Cells usando il metodo ShapeCollection.AddActiveXControl(). Questo metodo richiede un parametro ControlType che indica che tipo di controllo ActiveX deve essere aggiunto all’interno di un foglio di lavoro. Ha i seguenti valori.
- ControlType.CheckBox
- ControlType.ComboBox
- ControlType.CommandButton
- ControlType.Image
- ControlType.Label
- ControlType.ListBox
- ControlType.RadioButton
- ControlType.ScrollBar
- ControlType.SpinButton
- ControlType.TextBox
- ControlType.ToggleButton
- ControlType.Unknown
Una volta aggiunto il controllo ActiveX all’interno della raccolta delle forme, puoi accedere all’oggetto di controllo ActiveX tramite la proprietà Shape.ActiveXControl e quindi impostarne varie proprietà.
Il seguente codice di esempio aggiunge il pulsante di controllo ActiveX utilizzando Aspose.Cells.
// 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); |