我想用Basic在LibreOffice表单中迭代控件。
基本上,我想做这段代码在VBA中所做的工作。
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的帮助下发现的。这还不完全正确。我不能拿到控制器的标签。
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发布于 2015-04-15 16:44:09
注意:这段代码是在OpenOffice中测试的。我相信它在LibreOffice中也会以同样的方式工作。
控件位于绘图页上。如果可能有不可控制的绘图对象(箭头、形状、图像等)如果您只想在控件上操作,则必须遍历所有绘制对象,并测试每个对象是否为控件:
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“。哇哦!(我曾经使用过其他对象,这些对象只有通过“模型”才能访问某些属性;这不是一个直观的查看位置。)
所以试试这个:
For Each cControl In Controls
I = I + 1
A = A & cControl.getModel.Label
Next cControlhttps://stackoverflow.com/questions/29652600
复制相似问题