首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用LibreOffice Basic迭代控件

使用LibreOffice Basic迭代控件
EN

Stack Overflow用户
提问于 2015-04-15 14:10:51
回答 1查看 1.4K关注 0票数 0

我想用Basic在LibreOffice表单中迭代控件。

基本上,我想做这段代码在VBA中所做的工作。

代码语言:javascript
复制
Sub parcours_controles_formulaire()
    Dim cControl As Control
    Dim sLog As String
    sLog = "List of controls : " & vbCrLf 
    For Each cControl In FrmExemplesControles.Controls
        sLog = sLog & _
        cControl.Name & _
        " of type " & _
        TypeName(cControl) & vbCrLf
    Next cControl
    MsgBox sLog
End Sub

编辑:是我在Lyrl的帮助下发现的。这还不完全正确。我不能拿到控制器的标签。

代码语言:javascript
复制
Sub iterate_forms_controls()
    Dim Dlg As Object
    Dim Controls As Object
    Dim cControl As Object
    Dim I As Integer
    Dim A As String

    DialogLibraries.LoadLibrary("Standard")
    Dlg = CreateUnoDialog(DialogLibraries.Standard.BoiteDeDialogue1)

    Controls = Dlg.Controls

    I = 0
    A = ""
    For Each cControl In Controls
        I = I + 1
        A = A & cControl.getImplementationName()
        'A = A & cControl  ' How to get back the label of cControl here ?
    Next cControl

    MsgBox "There is " & i & " controls in that form !" & A
End Sub
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-04-15 16:44:09

注意:这段代码是在OpenOffice中测试的。我相信它在LibreOffice中也会以同样的方式工作。

控件位于绘图页上。如果可能有不可控制的绘图对象(箭头、形状、图像等)如果您只想在控件上操作,则必须遍历所有绘制对象,并测试每个对象是否为控件:

代码语言:javascript
复制
Sub iterate_forms_controls()
    Dim oDP As Object : oDP = ThisComponent.drawpage
    Dim cControl As Object
    Dim i As Integer

    REM The oDP assignment above is for a standard form (a Writer document).
    REM If you are using a Calc document as a form you would instead write:
    REM oDP = ThisComponent.Sheets.getByName("SheetName").drawpage

    For i = 0 To oDP.Count - 1
    cControl = oDP.getByIndex(i)
        If cControl.supportsService("com.sun.star.drawing.ControlShape") Then
            'Do something
        End If
    Next i
End Sub

编辑:我看了XRay的对象"cControl“。仔细看了看这些属性,没有任何东西看起来有用。然后我去了方法,并找到了一个方法"getModel“。在getModel上双击XRay方法,并找到带有我给出的复选框的名称的"Label“。哇哦!(我曾经使用过其他对象,这些对象只有通过“模型”才能访问某些属性;这不是一个直观的查看位置。)

所以试试这个:

代码语言:javascript
复制
For Each cControl In Controls
    I = I + 1
    A = A & cControl.getModel.Label
Next cControl
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29652600

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档