【问题标题】:OpenOffice BASIC how to insert checkbox in sheetOpenOffice BASIC 如何在工作表中插入复选框
【发布时间】:2016-05-18 18:34:35
【问题描述】:

我正在使用 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 位置)。 我在互联网上搜索,但我只找到有关将控件插入对话框而不是工作表的信息

【问题讨论】:

    标签: vba macros openoffice.org openoffice-calc openoffice-basic


    【解决方案1】:

    要手动创建复选框,请参阅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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-01-08
      • 1970-01-01
      • 2011-09-05
      • 1970-01-01
      • 2011-06-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多