[Base] How to add a report and formatted fields in it using a macro?

asked 2015-02-16 16:52:01 +0200

felix_2015 gravatar image

I use LO in French on Debian Jessie also in French and try to add a report and formatted fields in it using a macro. I used createunoservice function to create my objects but it didn't work. That is to say I get no errors but it doesn't work. I ask this question everywhere on Internet and get no answers. I don't know whether it is difficult or not to do. Here is what I did:

REM  *****  BASIC  *****
Option Explicit

sub createReport
dim oConnection as object
dim oReportsDocuments as object
dim oReportDesign as object
dim oField as object

oConnection = ThisDatabaseDocument.DataSource.getconnection("","")

oReportsDocuments = ThisDatabaseDocument.ReportDocuments

'trying to create a new report
oReportDesign = createUnoService("com.sun.star.report.ReportDefinition")
oReportDesign.setPropertyValue("ActiveConnection", oConnection)
oReportDesign.Command = "Table1"
oReportDesign.Name = "monrapport"
oReportDesign.caption = "legende"

'trying to add a new formatted field
oField = createUnoService("com.sun.star.report.FormattedField")
with oField
    .name = "field1"
    .DataField = "field:[champ1]"
    '.positionX = 14000 REM marche pô (pas d'erreur mais pas pris en compte)
    '.positionY = 0 REM marche pô 
    .width = 2000
    .height = 500
end with

'trying to add it to the reports
oReportsDocuments.insertbyname("monrapport", oReportDesign)
end sub

Thanks for your help.

edit retag flag offensive close merge delete


Is the line at the end, oReportsDocuments.insertbyname, looking for the object type "com.sun.star.comp.dba.ODocumentDefinition"? That is the object type you would receive by the getByName method. Not sure how that fits with the main object you are editing, "com.sun.star.report.ReportDefinition" Alternatively, what if you filled in more of the properties of oReportDesign.

doug gravatar imagedoug ( 2015-02-20 05:09:15 +0200 )edit