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
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
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 Expand viewCollapse view
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!
Correo electrónico
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
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 Expand viewCollapse view
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
Users browsing this forum: No registered users and 0 guests