Aspose.Cells を使用して ActiveX コントロールを追加する
ShapeCollection.AddActiveXControl() メソッドを使用して Aspose.Cells で ActiveX コントロールを追加することができます。 このメソッドは、ワークシート内に追加する ActiveX コントロールの種類を伝えるパラメータ ControlType を取ります。 次の値があります。
- ControlType.CheckBox
- ControlType.ComboBox
- ControlType.CommandButton
- ControlType.Image
- ControlType.Label
- ControlType.ListBox
- ControlType.RadioButton
- ControlType.ScrollBar
- ControlType.SpinButton
- ControlType.TextBox
- ControlType.ToggleButton
- ControlType.Unknown
シェイプコレクション内に ActiveX コントロールを追加したら、それから Shape.ActiveXControl プロパティを介して ActiveX コントロール オブジェクトにアクセスし、そのさまざまなプロパティを設定できます。
Aspose.Cellsを使用してToggle Button ActiveXコントロールを追加するサンプルコードは、次のとおりです。
| // 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 = "./"; | |
| // 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); |