OpenOffice BASIC 如何在 sheet 中插入复选框

OpenOffice BASIC how to insert checkbox in sheet

我正在使用 OpenOffice Calc。 我正在 OpenOffice BASIC 中编写宏。 我需要正确的代码在 sheet.

中插入一个复选框

我现在有

Dim Doc as Object
Doc = ThisComponent
Dim cbName As Object
cbName = "checkbox_name"

Dim oCheckBoxModel as Object

// dlg is a dialog, (don't know how to create a checkbox else)
oCheckBoxModel = dlg.getmodel().createInstance( "com.sun.star.awt.UnoControlCheckBoxModel" )
oCheckBoxModel.PositionX = 100
oCheckBoxModel.PositionY = 100
oCheckBoxModel.Width = 50
oCheckBoxModel.Height = 30
oCheckBoxModel.Label = id
oCheckBoxModel.Name = cbName
oCheckBoxModel.Enabled = True
oCheckBoxModel.TabIndex = 1
Doc.Sheets().insertByName( cbName, oCheckBoxModel ) // This line is totally wrong, but I hope it's clear what I want to do

所以我想创建一个复选框,然后将其插入 sheet。 (在特定单元格中,或仅通过设置 X 和 Y 位置)。 我在 Internet 上搜索,但我只找到有关将控件插入对话框的信息,而不是 sheet

要手动创建复选框,请参阅 here。动态创建复选框:

Sub CreateCheckbox
  oDoc = ThisComponent
  oSheet = oDoc.Sheets.getByIndex(0)
  oDrawPage = oSheet.DrawPage  'Was oDrawPage = oDoc.getDrawPage()
  oCheckboxModel = AddNewCheckbox("Checkbox_1", "Check this box", oDoc, oDrawPage)
End Sub

Function AddNewCheckbox(sName As String, sLabel As String, _
    oDoc As Object, oDrawPage As Object) As Object
  oControlShape = oDoc.createInstance("com.sun.star.drawing.ControlShape")
  aPoint = CreateUnoStruct("com.sun.star.awt.Point")
  aSize = CreateUnoStruct("com.sun.star.awt.Size")
  aPoint.X = 1000
  aPoint.Y = 1000
  aSize.Width = 3000
  aSize.Height = 1000
  oControlShape.setPosition(aPoint)
  oControlShape.setSize(aSize)

  oButtonModel = CreateUnoService("com.sun.star.form.component.CheckBox")
  oButtonModel.Name = sName
  oButtonModel.Label = sLabel

  oControlShape.setControl(oButtonModel)
  oDrawPage.add(oControlShape)

  AddNewCheckbox = oButtonModel
End Function

此代码改编自 https://forum.openoffice.org/en/forum/viewtopic.php?f=45&t=46391