How to create multi line header in report?

Getting your data onto paper - or the web - Discussing the reports features of Base
Post Reply
dreamquartz
Posts: 881
Joined: Mon May 30, 2011 4:02 am

How to create multi line header in report?

Post by dreamquartz »

Hello All,

Need to create a Report, based on a Query, with a multi line header (similar to Ctrl+Enter in Calc).
Does anyone know how to do something like that?

Thanks in advance,

Dream
LO 7.x, HSQLDB 2.7.x & Ubuntu 22.04 LTS.
longi
Posts: 110
Joined: Mon Jul 15, 2013 5:04 pm

Re: How to create multi line header in report?

Post by longi »

Hi!
I supose you are using ORB (I've read some posts from you).
The simpliest ORB report has three tables, but the normal thing is to use for data the second one ('Main table'). So, I wrote this little macro in order to get the Autoheight property in the first row on the 'Main table'.
If it is not the case, you can adapt it for every row or table you want.

Code: Select all

Sub Report
    Dim oreportdoc As Object, ocontroller
    Dim i As Integer
    Dim oTextTable As Variant, Fila As Object
    '------------------------------------------------------------------------
    ' We'll open the report
    
    ocontroller = Thisdatabasedocument.currentController                                              ' The present data Base
    if not ocontroller.isconnected then ocontroller.connect                                           ' We keep the conection
    oreportdoc = Thisdatabasedocument.reportdocuments.getbyname("Your report").open                   ' We open the report
    oTexttable = oreportdoc.Texttables(2)                                                             ' The main table
    oTexttable.getRows().getByIndex(0).IsAutoHeight = True                                            ' Autoheight
End Sub
Bye! :)
OpenOffice 4.1.5 on Windows 10
LibreOffice 5.1 on Windows 7
LibreOffice 6.0.1 on Windows10
dreamquartz
Posts: 881
Joined: Mon May 30, 2011 4:02 am

Re: How to create multi line header in report?

Post by dreamquartz »

longi wrote:Hi!
I supose you are using ORB (I've read some posts from you).
The simpliest ORB report has three tables, but the normal thing is to use for data the second one ('Main table'). So, I wrote this little macro in order to get the Autoheight property in the first row on the 'Main table'.
If it is not the case, you can adapt it for every row or table you want.

Code: Select all

Sub Report
    Dim oreportdoc As Object, ocontroller
    Dim i As Integer
    Dim oTextTable As Variant, Fila As Object
    '------------------------------------------------------------------------
    ' We'll open the report
    
    ocontroller = Thisdatabasedocument.currentController                                              ' The present data Base
    if not ocontroller.isconnected then ocontroller.connect                                           ' We keep the conection
    oreportdoc = Thisdatabasedocument.reportdocuments.getbyname("Your report").open                   ' We open the report
    oTexttable = oreportdoc.Texttables(2)                                                             ' The main table
    oTexttable.getRows().getByIndex(0).IsAutoHeight = True                                            ' Autoheight
End Sub
Bye! :)
Hi Longi,

Thank you for your response.
We are hoping to solve the issue via SQL, because we would like to avoid macros at all costs. They are 'evil' (according to Villeroy, me, and many others including our Client).

Realized that I have to provide more information.
We use the Report function in many occasions for importing our information into other external databases.
We use the csv-format, because it is widely accepted.

Our DataBase holds information that needs to imported into an other database, of which we have no control.
The other database is external, and run by an independent organization.
What we suspect that it is a database with Microsoft involved one way or an other.

Their datase does allow csv-, xls-, and xslx-format import of information.
However the csv-format import does not work at all at this point.
A statement like: "Either File not selected or selected file does not contain any data, please validate file." indicates that the headings cannot be read.

The organization provided a template for import, based on the xlsx-format, but that does not work for the Reporter used by Base.
The Reporter in Base can only produce a txt- or csv- format report.
Note: We would love to provide the template, but are not allowed (protected information :().

The headings of the template are made up of text in 2 languages and 2 lines; 1st line: English, 2nd line: Spanish.
We are trying to duplicate the headings of the template via a Query.
Example of Header:
Email
Correo electrónico
We do not know if there is a Carriage Return (\r) or a New Line (\n) for the 2nd line.
We do know that the text is wrapped automatically.

We are quite sure that there is something with the template that we cannot reproduce, because if we copy the resultset of the Query in the template by hand :( and import the information, the import is successful.
If we copy the headings by hand :( into the resultset of the Report (csv-format) and save it as an LO xslx-format, the import works.

We are at a loss right now in creating a Report that can be used.

Kind regards,

Dream.
Last edited by RoryOF on Fri Mar 16, 2018 9:03 pm, edited 1 time in total.
Reason: Removed multiple pastes of previous posting [RoryOF, Moderator]
LO 7.x, HSQLDB 2.7.x & Ubuntu 22.04 LTS.
longi
Posts: 110
Joined: Mon Jul 15, 2013 5:04 pm

Re: How to create multi line header in report?

Post by longi »

Well!
At the end I couldn't catch the exactly point (my English skils, you Know!).
I supose that you need to export a query into a xlsx sheet, which is a template in order to offer your data to another (and external) database.
If this is the point I have (I think) a solution, but the solution is by code (Sorry!)
Macros are evil, you're right, however, if they are well done they make our work easier than before. (I don't guarantee that my code is well done, of course!)
You have to put in the line 29 the name of your query and in the line 57 the route of your template.
If you run it, it will copy the query and paste it in the first cell of your template, but that could be changed too in line 64.
If your question is different that I understood, I sorry (my English skils, you Know! :( )

Code: Select all

Sub Consulta1    
    
    NombreBase = FileNameOutOfPath( ThisDatabasedocument.getURL() )                         ' Nombre de la base en la que estamos
    RutaBase= ConvertFromURL(DirectoryNameoutofPath (ThisDatabasedocument.getURL,"/",0))    ' Ruta de la base en la que estamos
    '---------------------------------------------------------
    ' Accedemos al panel de consultas. El programa externo escoge la consulta

    oDoc = ThisDatabasedocument                                                             ' La base de datos en la que estamos
    oDisp = createUnoService("com.sun.star.frame.DispatchHelper")                           ' Servicio de despachador
    oFrame = oDoc.getCurrentController().getFrame()                                         ' El marco en el que nos movemos
    oDisp.executeDispatch(oFrame, ".uno:DBViewQueries", "",0 , Array())                     ' Accedemos al panel de consultas
    oDocumentos = StarDesktop.getComponents()                                               ' Documentos que hay en el escritorio
    oEnumeraDocumentos = oDocumentos.createEnumeration()                                    ' Enumeramos los documentos
    Do While oEnumeraDocumentos.hasMoreElements()                                           ' Mientras haya más elementos
    oDocumento = oEnumeraDocumentos.nextElement()                                           ' Vamos al siguiente
    If HasUnoInterfaces(oDocumento, "com.sun.star.frame.XModel") Then                       ' Si tiene modelo
    If oDocumento.getTitle()=NombreBase Then                                                ' Si tiene el título que nos interesa (el nombre de la base de datos)
    document= oDocumento.CurrentController.Frame                                            ' Determinamos el marco (Frame)
    oVentana = oDocumento.getCurrentController.getFrame.getComponentWindow()                ' Ventana en el marco
    oVentana.setFocus()                                                                     ' Enfocamos
    '------------------------------------------------------
    ' Usamos la herramienta WScript
    
    set oWSObj = CreateObject("WScript.Shell")                                              ' Creamos el objeto
    Wait 100                                                                                ' Esperamos un poco
	oWSObj.SendKeys "{TAB}"                                                                 ' Como si presionásemos la tecla 'TAB'
	oWSObj.SendKeys "{TAB}"                                                                 ' Como si presionásemos la tecla 'TAB'
	oWSObj.SendKeys "{TAB}"                                                                 ' Como si presionásemos la tecla 'TAB'
    oWSObj.SendKeys "Your query"                                                            ' Ponemos la consulta que queremos
    Wait 100                                                                                ' Esperamos un poco
    oDisp.executeDispatch(oFrame, ".uno:Copy", "", 0, Array())                              ' Copiamos la consulta
    End if                                                                                  ' Acabamos la condición de que sea la base de datos
    End if                                                                                  ' Acabamos la condición del interfaz
    loop                                                                                    ' Vamos al siguiente elemento
    '---------------------------------------------------------
    ' Volvemos al formulario
    
    oDocumentos = StarDesktop.getComponents()                                               ' Documentos que hay en el escritorio
    oEnumeraDocumentos = oDocumentos.createEnumeration()                                    ' Enumeramos los documentos
    Do While oEnumeraDocumentos.hasMoreElements()                                           ' Mientras haya más elementos
    oDocumento = oEnumeraDocumentos.nextElement()                                           ' Vamos al siguiente
    If HasUnoInterfaces(oDocumento, "com.sun.star.frame.XModel") Then                       ' Si tiene modelo
    If oDocumento.getTitle()= NombreBase &" : " & "Your main form" Then                     ' Si tiene el nombre que queremos (El formulario)
    document= oDocumento.CurrentController.Frame                                            ' Determinamos el marco (Frame)
    oVentana = oDocumento.getCurrentController.getFrame.getComponentWindow()                ' Ventana en el marco
    oVentana.setFocus()                                                                     ' Enfocamos
    End if                                                                                  ' Acabamos la condición de que sea la base de datos
    End if                                                                                  ' Acabamos la condición del interfaz
    loop                                                                                    ' Vamos al siguiente elemento
    '-------------------------------------------------------
    ' A	brimos el Calc de destino

    Dim mOpciones0(0) As New "com.sun.star.beans.PropertyValue"                             ' Array de opciones
    mOpciones0(0).Name = "Hidden"                                                           ' Nombre de la propiedad 'Escondido'
    mOpciones0(0).Value= False                                                              ' Trabajamos en segundo plano
    Dim mArg()
    sRuta = ConvertToUrl( "C:\Users\...\....\Your template" )
    oDocumento = StarDesktop.loadComponentFromURL( sRuta, "_blank", 0, mArg() )

'    oDocumento=StarDesktop.loadComponentFromURL("private:factory/scalc","_blank",0,mOpciones0())' Hoja de cálculo que se abre, pero aún no se ve
    document= oDocumento.CurrentController.Frame                                            ' Determinamos el marco (Frame)
    dim args1(0) as new com.sun.star.beans.PropertyValue                                    ' Array de acciones
    args1(0).Name = "ToPoint"                                                               ' Nombre de la acción
    args1(0).Value = "$A$1"                                                                 ' Seleccionamos la celda A2
    oDisp.executeDispatch(document, ".uno:GoToCell", "", 0, args1())                        ' Nos colocamos en la celda
    oDisp.executeDispatch(document, ".uno:Paste", "", 0, Array())                           ' Pegamos lo copiado
    document.ContainerWindow.Visible = True                                                 ' Hacemos la ventana visible
    document.ContainerWindow.toFront()                                                      ' La traemos al frente
    Exit sub
    '------------------------------------------------------------
    ' Error control

    oBad:		
	Dim oErLine As Integer
	Dim oErNum As Integer
	Dim oErMsg As String
		oErLine = Erl
		oErNum = Err
		oErMsg = Error
		Msgbox("Error Line No. " & Chr$(9) & " : " & oErLine & Chr$(10) _
			& "Error Number " & Chr$(9) & " : " & oErNum &Chr$(10 ) _
			& "Error Message" & Chr$(9) & " : " & oErMsg , 0, "Error Message")


End sub
  
OpenOffice 4.1.5 on Windows 10
LibreOffice 5.1 on Windows 7
LibreOffice 6.0.1 on Windows10
dreamquartz
Posts: 881
Joined: Mon May 30, 2011 4:02 am

Re: How to create multi line header in report?

Post by dreamquartz »

longi wrote:Well!
At the end I couldn't catch the exactly point (my English skils, you Know!).
I supose that you need to export a query into a xlsx sheet, which is a template in order to offer your data to another (and external) database.
If this is the point I have (I think) a solution, but the solution is by code (Sorry!)
Macros are evil, you're right, however, if they are well done they make our work easier than before. (I don't guarantee that my code is well done, of course!)
You have to put in the line 29 the name of your query and in the line 57 the route of your template.
If you run it, it will copy the query and paste it in the first cell of your template, but that could be changed too in line 64.
If your question is different that I understood, I sorry (my English skils, you Know! :( )

Code: Select all

Sub Consulta1    
    
    NombreBase = FileNameOutOfPath( ThisDatabasedocument.getURL() )                         ' Nombre de la base en la que estamos
    RutaBase= ConvertFromURL(DirectoryNameoutofPath (ThisDatabasedocument.getURL,"/",0))    ' Ruta de la base en la que estamos
    '---------------------------------------------------------
    ' Accedemos al panel de consultas. El programa externo escoge la consulta

    oDoc = ThisDatabasedocument                                                             ' La base de datos en la que estamos
    oDisp = createUnoService("com.sun.star.frame.DispatchHelper")                           ' Servicio de despachador
    oFrame = oDoc.getCurrentController().getFrame()                                         ' El marco en el que nos movemos
    oDisp.executeDispatch(oFrame, ".uno:DBViewQueries", "",0 , Array())                     ' Accedemos al panel de consultas
    oDocumentos = StarDesktop.getComponents()                                               ' Documentos que hay en el escritorio
    oEnumeraDocumentos = oDocumentos.createEnumeration()                                    ' Enumeramos los documentos
    Do While oEnumeraDocumentos.hasMoreElements()                                           ' Mientras haya más elementos
    oDocumento = oEnumeraDocumentos.nextElement()                                           ' Vamos al siguiente
    If HasUnoInterfaces(oDocumento, "com.sun.star.frame.XModel") Then                       ' Si tiene modelo
    If oDocumento.getTitle()=NombreBase Then                                                ' Si tiene el título que nos interesa (el nombre de la base de datos)
    document= oDocumento.CurrentController.Frame                                            ' Determinamos el marco (Frame)
    oVentana = oDocumento.getCurrentController.getFrame.getComponentWindow()                ' Ventana en el marco
    oVentana.setFocus()                                                                     ' Enfocamos
    '------------------------------------------------------
    ' Usamos la herramienta WScript
    
    set oWSObj = CreateObject("WScript.Shell")                                              ' Creamos el objeto
    Wait 100                                                                                ' Esperamos un poco
	oWSObj.SendKeys "{TAB}"                                                                 ' Como si presionásemos la tecla 'TAB'
	oWSObj.SendKeys "{TAB}"                                                                 ' Como si presionásemos la tecla 'TAB'
	oWSObj.SendKeys "{TAB}"                                                                 ' Como si presionásemos la tecla 'TAB'
    oWSObj.SendKeys "Your query"                                                            ' Ponemos la consulta que queremos
    Wait 100                                                                                ' Esperamos un poco
    oDisp.executeDispatch(oFrame, ".uno:Copy", "", 0, Array())                              ' Copiamos la consulta
    End if                                                                                  ' Acabamos la condición de que sea la base de datos
    End if                                                                                  ' Acabamos la condición del interfaz
    loop                                                                                    ' Vamos al siguiente elemento
    '---------------------------------------------------------
    ' Volvemos al formulario
    
    oDocumentos = StarDesktop.getComponents()                                               ' Documentos que hay en el escritorio
    oEnumeraDocumentos = oDocumentos.createEnumeration()                                    ' Enumeramos los documentos
    Do While oEnumeraDocumentos.hasMoreElements()                                           ' Mientras haya más elementos
    oDocumento = oEnumeraDocumentos.nextElement()                                           ' Vamos al siguiente
    If HasUnoInterfaces(oDocumento, "com.sun.star.frame.XModel") Then                       ' Si tiene modelo
    If oDocumento.getTitle()= NombreBase &" : " & "Your main form" Then                     ' Si tiene el nombre que queremos (El formulario)
    document= oDocumento.CurrentController.Frame                                            ' Determinamos el marco (Frame)
    oVentana = oDocumento.getCurrentController.getFrame.getComponentWindow()                ' Ventana en el marco
    oVentana.setFocus()                                                                     ' Enfocamos
    End if                                                                                  ' Acabamos la condición de que sea la base de datos
    End if                                                                                  ' Acabamos la condición del interfaz
    loop                                                                                    ' Vamos al siguiente elemento
    '-------------------------------------------------------
    ' A	brimos el Calc de destino

    Dim mOpciones0(0) As New "com.sun.star.beans.PropertyValue"                             ' Array de opciones
    mOpciones0(0).Name = "Hidden"                                                           ' Nombre de la propiedad 'Escondido'
    mOpciones0(0).Value= False                                                              ' Trabajamos en segundo plano
    Dim mArg()
    sRuta = ConvertToUrl( "C:\Users\...\....\Your template" )
    oDocumento = StarDesktop.loadComponentFromURL( sRuta, "_blank", 0, mArg() )

'    oDocumento=StarDesktop.loadComponentFromURL("private:factory/scalc","_blank",0,mOpciones0())' Hoja de cálculo que se abre, pero aún no se ve
    document= oDocumento.CurrentController.Frame                                            ' Determinamos el marco (Frame)
    dim args1(0) as new com.sun.star.beans.PropertyValue                                    ' Array de acciones
    args1(0).Name = "ToPoint"                                                               ' Nombre de la acción
    args1(0).Value = "$A$1"                                                                 ' Seleccionamos la celda A2
    oDisp.executeDispatch(document, ".uno:GoToCell", "", 0, args1())                        ' Nos colocamos en la celda
    oDisp.executeDispatch(document, ".uno:Paste", "", 0, Array())                           ' Pegamos lo copiado
    document.ContainerWindow.Visible = True                                                 ' Hacemos la ventana visible
    document.ContainerWindow.toFront()                                                      ' La traemos al frente
    Exit sub
    '------------------------------------------------------------
    ' Error control

    oBad:		
	Dim oErLine As Integer
	Dim oErNum As Integer
	Dim oErMsg As String
		oErLine = Erl
		oErNum = Err
		oErMsg = Error
		Msgbox("Error Line No. " & Chr$(9) & " : " & oErLine & Chr$(10) _
			& "Error Number " & Chr$(9) & " : " & oErNum &Chr$(10 ) _
			& "Error Message" & Chr$(9) & " : " & oErMsg , 0, "Error Message")


End sub
  
Thanks for your response, and sorry for my late response.
To clarify.
What I would like to accomplish is something similar as the headings that can be created in Calc.
Calc allows the row headings to have a /n or /r as character. This can be created via Ctrl-Return.
I am not sure which one, but is appears to be the /r, because both gedit and Writer treat the csv-format as a new line.
The problem is however that the new line start with a Capitalized character. This is unacceptable behavior for my purposes.

What happens is that the heading can then be fixed over more than one line, not dependent on the column width.
By creating a report in Base and setting the output to a csv-format, I would like to create the same, without capitalized 1st character, but this eludes me so far.

Our client is quite clear in NOT willing to add macros to their database, so programming apparently falls under that too :?

Dream
LO 7.x, HSQLDB 2.7.x & Ubuntu 22.04 LTS.
Post Reply