Ask Your Question
1

LibreOffice Calc File selection Path

asked 2018-02-16 18:58:03 +0200

peppinosh gravatar image

updated 2018-02-17 16:01:17 +0200

librebel gravatar image

Hi, I need to be able to insert the path of the file selected by the button inside a cell. how do I link a file selection button to a cell?

edit retag flag offensive close merge delete

Comments

I edited the title, changed "Libre-Cacl" into "LibreOffice Calc".

librebel gravatar imagelibrebel ( 2018-02-17 16:02:21 +0200 )edit

1 Answer

Sort by » oldest newest most voted
0

answered 2018-02-17 15:59:50 +0200

librebel gravatar image

Hello @peppinosh,

To physically link a File Selection button to a Calc cell, you could just right-click on the File Selection button ( in Design Mode ), and then choose the menuitem Anchor : To Cell.

Alternatively, you could set this same option via the Properties Dialog of your File Selection button.

If you then position the File Selection button into the anchor cell, it will physically move along with the cell when a new row or column is inserted, and it will grow or shrink along with the cell, when the cell is resized.

However it not a data link, and the chosen File Path from the File Selection button will not be automatically transferred into the cell.

In order to automatically transfer the chosen File Path into the anchor cell, you could connect the following basic macro to the “Text modified” event of your File Selection button:

code:

Sub on_FileSelection_TextModified( oEvent )
REM Connect this macro to the "Text modified" event of a FileSelection control that is anchored to a Spreadsheet Cell.
REM The Selected File Path should then automatically be inserted into the Anchor Cell.
REM See: https://ask.libreoffice.org/en/question/146558/libre-cacl-file-selection-path/
    Dim oControlModel As Object : oControlModel = oEvent.Source.getModel()
    Dim oDrawPages As Object    : oDrawPages    = ThisComponent.getDrawPages()      REM Assumes Calc document.
    Dim oDrawPage As Object
    Dim oShape As Object
    Dim i As Long, j As Long
    For i = 0 To oDrawPages.getCount() - 1      REM Find ControlShape to get the Anchor:
        oDrawPage = oDrawPages.getByIndex( i )
        For j = 0 To oDrawPage.getCount() - 1
            oShape = oDrawPage.getByIndex( j )
            If oShape.getShapeType() = "com.sun.star.drawing.ControlShape" Then
                Dim oControl As Object : oControl = oShape.getControl()
                If oControlModel.getName() = oControl.getName() Then        REM Found our FileSelection control.
                    Dim oAnchor As Object : oAnchor = oShape.getAnchor()
                    oAnchor.setString( oControl.Text )
                    Stop
                End If
            End If
        Next j
    Next i
End Sub

With Regards, lib


To mark this answer as correct, please click on the round checkmark icon on the left, and karma-permitting upvote it.

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2018-02-16 18:58:03 +0200

Seen: 109 times

Last updated: Feb 17 '18