Libreoffice Libre Office自定义对话框表

Libreoffice Libre Office自定义对话框表,libreoffice,libreoffice-basic,openoffice-basic,Libreoffice,Libreoffice Basic,Openoffice Basic,我正在创建一个自定义对话框,用户应该在其中选择多个可能的条目之一。我使用列表框列出可能要从中选择的条目 每行有多个变量,因此我想使用一个表来正确地对齐条目。是否有可能这样做 我所拥有的: abcdefg hijkl mnopq abcd efghijk lmno 我想要的是: abcdefg hijkl mnopq abcd efghilkl mno 为列表框使用固定宽度的字体,并用空格填充字符串 子填充ListBoxItems oListBox.addItems

我正在创建一个自定义对话框,用户应该在其中选择多个可能的条目之一。我使用列表框列出可能要从中选择的条目

每行有多个变量,因此我想使用一个表来正确地对齐条目。是否有可能这样做

我所拥有的:

abcdefg hijkl mnopq
abcd efghijk lmno
我想要的是:

abcdefg   hijkl      mnopq
abcd      efghilkl   mno

为列表框使用固定宽度的字体,并用空格填充字符串

子填充ListBoxItems
oListBox.addItems(数组(
PaddedItem(数组(“abcdefg”、“hijkl”、“mnopq”),
PaddedItem(数组(“abcd”、“efghijk”、“lmno”)),0)
端接头
函数PaddedItem(项字符串作为数组)
PaddedItem=焊盘串(项目_串(0)、10)和_
焊盘串(项目_串(1)、11)和项目_串(2)
端函数
函数PadString(strSource为字符串,lPadLen为长)
PadString=strSource&“”
如果Len(strSource)

在Basic中填充字符串的更多方法位于,尽管并非所有方法都适用于LibreOffice Basic。

对列表框使用固定宽度字体,并在字符串中填充空格

子填充ListBoxItems
oListBox.addItems(数组(
PaddedItem(数组(“abcdefg”、“hijkl”、“mnopq”),
PaddedItem(数组(“abcd”、“efghijk”、“lmno”)),0)
端接头
函数PaddedItem(项字符串作为数组)
PaddedItem=焊盘串(项目_串(0)、10)和_
焊盘串(项目_串(1)、11)和项目_串(2)
端函数
函数PadString(strSource为字符串,lPadLen为长)
PadString=strSource&“”
如果Len(strSource)
在Basic中填充字符串的更多方法位于,尽管并非所有方法都适用于LibreOffice Basic。

是的,这是可能的

创建一个新对话框,并在底部添加标签。 创建新模块并添加以下代码:

Option Explicit
Option Base 0

Dim oDialog1 As Object, oDataModel As Object, oListener As Object

Sub OpenDialog()
    Dim oGrid As Object, oGridModel As Object, oColumnModel As Object, oCol As Object
    Dim oLabel1 As Object, rect(3) As Integer

    DialogLibraries.LoadLibrary("Standard")
    oDialog1 = CreateUnoDialog(DialogLibraries.Standard.Dialog1)
    oGridModel = oDialog1.getModel().createInstance("com.sun.star.awt.grid.UnoControlGridModel")

    oLabel1 = oDialog1.getModel().getByName("Label1")
    rect(0) = oLabel1.getPropertyValue("PositionX")
    rect(1) = 10
    rect(2) = oLabel1.getPropertyValue("Width")
    rect(3) = oLabel1.getPropertyValue("PositionY") - 2*rect(1)
    With oGridModel
        .PositionX = rect(0)
        .PositionY = rect(1)
        .Width = rect(2)
        .Height = rect(3)
    End With

    oColumnModel = oGridModel.ColumnModel
    oCol = oColumnModel.createColumn()
    oCol.Title = "Column 1"
    oColumnModel.addColumn(oCol)

    oCol = oColumnModel.createColumn()
    oCol.Title = "Column 2"
    oColumnModel.addColumn(oCol)

    oCol = oColumnModel.createColumn()
    oCol.Title = "Column 3"
    oColumnModel.addColumn(oCol)

    oDialog1.getModel().insertByName("grid", oGridModel)
    oGrid = oDialog1.getControl("grid")
    oListener = (CreateUnoListener("grid_", "com.sun.star.awt.grid.XGridSelectionListener"))
    oGrid.addSelectionListener(oListener)

    oDataModel = oGridModel.GridDataModel
    oDataModel.addRow("a", Array("abcdefg", "hijkl", "mnopq"))
    oDataModel.addRow("b", Array("abcd", "efghijk", "lmno"))

    oDialog1.execute()
    oDialog1.dispose()
End Sub
要获取所选行的值,请为
grid\u selectionChanged
事件添加侦听器:

Sub grid_selectionChanged(ev)
    Dim oRows() As Object, oLabel1 As Object, sCells(2) As String
    oRows = ev.Source.getSelectedRows()
    oLabel1 = oDialog1.getModel().getByName("Label1")
    sCells(0) = oDataModel.getRowData(oRows(0))(0)
    sCells(1) = oDataModel.getRowData(oRows(0))(1)
    sCells(2) = oDataModel.getRowData(oRows(0))(2)
    oLabel1.setPropertyValue("Label", "Selected values: " + sCells(0) + "," + sCells(1) + "," + sCells(2))
End Sub
如果所有操作都正确,通过运行
OpenDialog
您应该可以获得网格:

是的,这是可能的

创建一个新对话框,并在底部添加标签。 创建新模块并添加以下代码:

Option Explicit
Option Base 0

Dim oDialog1 As Object, oDataModel As Object, oListener As Object

Sub OpenDialog()
    Dim oGrid As Object, oGridModel As Object, oColumnModel As Object, oCol As Object
    Dim oLabel1 As Object, rect(3) As Integer

    DialogLibraries.LoadLibrary("Standard")
    oDialog1 = CreateUnoDialog(DialogLibraries.Standard.Dialog1)
    oGridModel = oDialog1.getModel().createInstance("com.sun.star.awt.grid.UnoControlGridModel")

    oLabel1 = oDialog1.getModel().getByName("Label1")
    rect(0) = oLabel1.getPropertyValue("PositionX")
    rect(1) = 10
    rect(2) = oLabel1.getPropertyValue("Width")
    rect(3) = oLabel1.getPropertyValue("PositionY") - 2*rect(1)
    With oGridModel
        .PositionX = rect(0)
        .PositionY = rect(1)
        .Width = rect(2)
        .Height = rect(3)
    End With

    oColumnModel = oGridModel.ColumnModel
    oCol = oColumnModel.createColumn()
    oCol.Title = "Column 1"
    oColumnModel.addColumn(oCol)

    oCol = oColumnModel.createColumn()
    oCol.Title = "Column 2"
    oColumnModel.addColumn(oCol)

    oCol = oColumnModel.createColumn()
    oCol.Title = "Column 3"
    oColumnModel.addColumn(oCol)

    oDialog1.getModel().insertByName("grid", oGridModel)
    oGrid = oDialog1.getControl("grid")
    oListener = (CreateUnoListener("grid_", "com.sun.star.awt.grid.XGridSelectionListener"))
    oGrid.addSelectionListener(oListener)

    oDataModel = oGridModel.GridDataModel
    oDataModel.addRow("a", Array("abcdefg", "hijkl", "mnopq"))
    oDataModel.addRow("b", Array("abcd", "efghijk", "lmno"))

    oDialog1.execute()
    oDialog1.dispose()
End Sub
要获取所选行的值,请为
grid\u selectionChanged
事件添加侦听器:

Sub grid_selectionChanged(ev)
    Dim oRows() As Object, oLabel1 As Object, sCells(2) As String
    oRows = ev.Source.getSelectedRows()
    oLabel1 = oDialog1.getModel().getByName("Label1")
    sCells(0) = oDataModel.getRowData(oRows(0))(0)
    sCells(1) = oDataModel.getRowData(oRows(0))(1)
    sCells(2) = oDataModel.getRowData(oRows(0))(2)
    oLabel1.setPropertyValue("Label", "Selected values: " + sCells(0) + "," + sCells(1) + "," + sCells(2))
End Sub
如果所有操作都正确,通过运行
OpenDialog
您应该可以获得网格: