0

我正在使用 OpenOffice Calc。我正在 OpenOffice BASIC 中编写宏。我需要正确的代码在工作表中插入一个复选框。

我现在有

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

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

4

1 回答 1

1

要手动创建复选框,请参见此处。动态创建复选框:

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

于 2016-05-20T14:16:19.460 回答