Call a Query from a Macro

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
dreamquartz
Posts: 918
Joined: Mon May 30, 2011 4:02 am

Call a Query from a Macro

Post by dreamquartz »

Hi All,

Trying to figure out to create a Macro in LO 26.2 under Ubuntu that accesses a Query, based in a Split HSQL DataBase.
The Query is used for creating a csv-format file that is to imported in an external MS program, that runs on a separate computer.
The program requires a certain file layout, hence this process.

The Query is now run manually, by doing the following:
1. Open a Calc Sheet
2. Ctrl+Shift+F4 (Data Sources)
3. Select and run Query.
Note: the Query requires User input.

I came to this point
Opening an existing document called: DataSources.ods.
NOTE: Would like to not do it this way. I would like to use a User Input for the Document Name, instead of 'fixed'.

Code: Select all

Sub NewOds
Dim docURL As String
        Dim doc As Object, docProperties()
        docURL = ConvertToURL("/home/.../Documents/DataSource.ods")
        Rem com.sun.star.frame.Desktop
        doc = StarDesktop.LoadComponentFromURL(docURL, "_blank", 0, docProperties)
End Sub
Result of Macro Recorder to see how the 2 can be integrated.
Should not be that complex for sure.

Code: Select all

sub OpenSource
rem ----------------------------------------------------------------------
rem define variables
dim document   as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

rem ----------------------------------------------------------------------
dim args1(0) as new com.sun.star.beans.PropertyValue
args1(0).Name = "ViewDataSourceBrowser"
args1(0).Value = true

dispatcher.executeDispatch(document, ".uno:ViewDataSourceBrowser", "", 0, args1())

rem ----------------------------------------------------------------------
dim args2(0) as new com.sun.star.beans.PropertyValue
args2(0).Name = "ViewDataSourceBrowser"
args2(0).Value = true

dispatcher.executeDispatch(document, ".uno:ViewDataSourceBrowser", "", 0, args2())

end Sub
What I found so far is that a SQL String can be used in a Macro.
What I not want to do is copy the Query in to the Macro, but call it by name.

Some guidance is appreciated.

Dream

PS: I am learning to understand......
LO 7.x, HSQLDB 2.7.x & Ubuntu 24.04 LTS.
User avatar
karolus
Volunteer
Posts: 1252
Joined: Sat Jul 02, 2011 9:47 am

Re: Call a Query from a Macro

Post by karolus »

Libreoffice 25.2… on Debian 13 (trixie) (on RaspberryPI5)
Libreoffice 25.8… flatpak on Debian 13 (trixie) (on RaspberryPI5)
Post Reply