Kirjautuminen

Haku

Tehtävät

Keskustelu: Koodit: LibreOffice dataset dokumentista valintaikkunaan

neosofta [23.04.2026 15:39:59]

#

Simppeli sample LibreOffice Writer dokumenttiin sijoitettuun Taulukko ohjausobjektiin tuodun datasetin sisällön siirtämisestä synkronoidusti Valintaikkunaan sijoitettuun Taulukko (Grid) ohjausobjektiin.

' Module1
REM  *****  BASIC  *****
REM Lisenssi: DWYFW (tee mitä v***** ikinä haluat)

Global oGlobalForm As Object
Global oDialog As Object
Private oLabel As Object
Private oFocusListener As Object
Private IsGained As Boolean
Private oDialogModel As Object
Private winW As Long
Private winH As Long
Private winX As Long
Private winY As Long
Private oWindow As Object

Sub MigrateAndSynchronize()

    Dim oController As Object
    Dim oFrame As Object
    Dim aPosSize As Object
    oController = thisComponent.CurrentController
    oFrame = oController.Frame
    oWindow = oFrame.ContainerWindow
    oWindowIsMaximized = True
    aPosSize = oWindow.PosSize
    winW = aPosSize.Width
    winH = aPosSize.Height
    winX = aPosSize.X
    winY = aPosSize.Y
    aPosSize = Nothing
    oFrame = Nothing
    oWindow = Nothing
    oController = Nothing

    Dim oTableControl As Object, oGridModel As Object
    Dim oColumnModel As Object, oDataModel As Object
    Dim i As Integer, n As Integer

    oGlobalForm = ThisComponent.DrawPage.Forms.getByIndex(0)
    oTableControl = oGlobalForm.getByName("TableControl1")

    oDialogModel = createUnoService("com.sun.star.awt.UnoControlDialogModel")
    oGridModel = oDialogModel.createInstance("com.sun.star.awt.grid.UnoControlGridModel")
    oGridModel.setPropertyValues(Array("Height", "PositionX", "PositionY", "Width", "SelectionModel"), _
                                 Array(150, 5, 5, 290, 1))
    oDialogModel.insertByName("DataGrid", oGridModel)

    oColumnModel = createUnoService("com.sun.star.awt.grid.DefaultGridColumnModel")
    For i = 0 To oTableControl.Count - 1
        Dim oColModel As Object
        oColModel = oColumnModel.createColumn()
        oColModel.Title = oTableControl.getByIndex(i).Label
        oColumnModel.addColumn(oColModel)
    Next i

    oGridModel.ColumnModel = oColumnModel

    oDataModel = createUnoService("com.sun.star.awt.grid.DefaultGridDataModel")
    oGlobalForm.first()

    Do While Not oGlobalForm.isAfterLast()
        Dim aRowData(oTableControl.Count - 1) As Variant
        For n = 0 To oTableControl.Count - 1
            Dim colName As String
            colName = oTableControl.getByIndex(n).DataField
            aRowData(n) = oGlobalForm.getString(oGlobalForm.findColumn(colName))
        Next n
        oDataModel.addRow("", aRowData)
        oGlobalForm.next()
    Loop

    oGridModel.GridDataModel = oDataModel

    oDialog = createUnoService("com.sun.star.awt.UnoControlDialog")
    oDialog.setModel(oDialogModel)
    Dim oGridControl As Object
    oGridControl = oDialog.getControl("DataGrid")
    Dim oListener As Object
    oListener = createUnoListener("GridHandler_", "com.sun.star.awt.grid.XGridSelectionListener")
    oGridControl.addSelectionListener(oListener)
    oDialog = createUnoService("com.sun.star.awt.UnoControlDialog")
    oDialog.setModel(oDialogModel)
    oDialogModel.setPropertyValues( _
    Array("Height", "Width", "PositionX", "PositionY", "Title"), _
    Array(180, 300, 1 , 1 , "Synchronized view"))

    Dim oLabelModel As Object
    oLabelModel = createUnoService("com.sun.star.awt.UnoControlFixedTextModel")
    oLabelModel.setPropertyValues( _
    Array("Height", "Width", "PositionX", "PositionY"), _
    Array(1, 1, 299, 179))
    oDialogModel.insertByName("Label1", oLabelModel)
    oLabel = oDialog.getControl("Label1")
    oLabel.Model.Enabled = True
    oLabel.Model.Border = 0
    oFocusListener = CreateUnoListener("FocusListener_","com.sun.star.awt.XFocusListener")
    oLabel.addFocusListener(oFocusListener)
    IsGained = False

    oDialog.setVisible(True)
    oLabel.setFocus
    oDialog.execute()

    thisComponent.unlockControllers
    thisComponent.setModified(False)
    oWindow.IsMaximized = True
    thisComponent.close(True)
    oDialog.dispose()

End Sub

Sub GridHandler_selectionChanged(oEvent)

    Dim nSelectedRow As Long
    Dim oGrid As Object

    oGrid = oEvent.Source
    If oGrid.hasSelectedRows() Then
        nSelectedRow = oGrid.getSelectedRows()(0)
        oGlobalForm.absolute(nSelectedRow + 1)
    End If
End Sub

Sub GridHandler_disposing(oEvent)
End Sub

Sub FocusListener_focusGained(oEvent)

    If Not IsGained Then

        IsGained = True
        oDialogModel.PositionX = CLng(winW / 7.77)
        oDialogModel.PositionY = CLng(winH / 7.77)
        thisComponent.lockControllers

        Dim oController As Object
        Dim oFrame As Object
        Dim oPosSize As Object
        oController = thisComponent.CurrentController
        oFrame = oController.Frame
        oWindow = oFrame.ContainerWindow
        aPosSize = oWindow.PosSize
        oWindow.IsMaximized = False

        oWindow.setPosSize(1000000,1000000, 0, 0, com.sun.star.awt.PosSize.POSSIZE)

    End If

End Sub

Sub FocusListener_focusLost : End Sub
Sub FocusListener_disposing : End Sub

REM NO WARRANTY 😎

Kuvaus ja toiminto selviää tsiigaamalla tämän

Halutessaan valmiin testiprojektin voi imaista täältä

HV (hyvää vappua jo etukäteen)

Vastaus

Muista lukea kirjoitusohjeet.
Tietoa sivustosta