Create a new Report Document using a Macro

Greetings everyone,

I’m coming to you with a quick, though perhaps complex question.

I am wondering if there is a method to insert a new Report document into a HSQLDB embedded database document in LibreOffice (24.2.2.2) using a Macro? What I am looking for is something similar to what Andrew Pitonyak demonstrated in his “AndrewBase” book, page 21, section 2.3.2, where he shows how to create a new Form document in a Database document using a Macro.

I attempted the same method to insert a Report document, however, unlike a Form, a Report is not a Writer document internally. A Form is a Writer document both in Design mode, and viewing mode. Whereas a Report is its own type of document, apparently a “application/vnd.sun.xml.report”, [according to “ContentType” in DatabaseDoc>ReportDocuments>getByIndex(0).ContentType], or a “com.sun.star.comp.report.OReportDefinition” according to the Report Document’s Implementation Name.

Either way, I can’t seem to find a way to create and save this type of document to the Database.

I tried just inserting a “com.sun.star.sdb.DocumentDefinition” service, which from what I understand from the OpenOffice Dev. guide, 3.1.0, Pg 1215 (1209 PDF), is supposed to insert a Form or a Report, depending on the container it is inserted into,

“The interface com.sun.star.lang.XMultiServiceFactory is used to create new forms or reports. The method createInstanceWithArguments() of XMultiServiceFactory creates a new document definition. Whether the document is a form or a report depends on the container where this object is inserted.”

Sub Main

Dim sURL

Dim sReportName

Dim oReportDocs

Dim oDocDef

Dim oConn

Dim oDB

Dim oProps(1) as new com.sun.star.beans.PropertyValue

oReportDocs = ThisComponent.getReportDocuments()

sURL = ThisComponent.URL()

oDBContext = createUnoService( "com.sun.star.sdb.DatabaseContext" )

oDB = oDBContext.getByName(sURL)

oConn = oDB.getConnection("", "")

sReportName = "New_Report2"

oProps(0).Name = "Name"

oProps(0).Value = sReportName

oProps(1).Name = "ActiveConnection"

oProps(1).Value = oConn

oDocDef = oReportDocs.createInstanceWithArguments("com.sun.star.sdb.DocumentDefinition", oProps())

oReportDocs.insertbyName(sReportName, oDocDef)

End Sub

However when I inserted the “DocumentDefinition” service, the result was a new entry as a Report without “ContentType” set, (empty string), which when opened, behaves as a Graphics document. I can create a new Report Document, opened and ready to be modified using a UNO Dispatch command (“.uno:DBNewReport”), but I can’t find a way to then save/insert it into the Database document’s storage.
I have also been able to successfully insert a new Report using the above Macro by copying an existing Report and adding the property EmbeddedObject to the array of properties. But this won’t completely be an answer if, for example there are no pre-existing reports to copy. Not to mention one would also have to wipe out all copied data to make the new Report be blank like a truly newly created one.

I am not looking to accomplish anything in particular beyond this specific request, i.e. creating a new Report Document using a Macro. Or to at least ascertain if it is even possible currently? I and a friend are working on allowing LibreOffice to be automated using AutoIt, and one of the things we are adding is modification of Reports and the like. Not that I am requesting help with the AutoIt portion of the code, simply some guidance on what needs created, and what needs to be inserted, or better yet, a Macro that can be run in Basic which would be easy to swap to work in AutoIt. What I am trying to say is I know a user can manually create a Report just as, or even easier, but if for some reason they wish to be able to automate creating a Report using AutoIt, I am hoping to be able to offer this ability.

Thank you for any guidance you may be able to offer,
Best regards,

Sounds like fun… But I would not try this with the report designer, wich is often not very stable/reliable. (In composing the reports, not running actual pre-createdbreports).
.
Sorry I can’t help with your project, but can give you one hint: The report designer is an extension, wich is incorporated to LibreOffice. For OpenOffice years ago I needed to install the extension by Oracle ourselves.) So I don’t expect it integrated with an API to LO.
You will find there an adittional hint: “The Oracle Report Builder uses the Pentaho Reporting Flow Engine of Pentaho BI.”
https://extensions.openoffice.org/en/project/oracle-report-builder
.
I find it often much easier to create Writer-Documents bound to datasources for mail-merge or linking Calc-Sheets to queries for some of my customized “reports”.