Macro para leer archivos cierra Openoffice

Discute sobre la aplicación de hojas de cálculo
Responder
rttsl
Mensajes: 20
Registrado: Jue May 14, 2015 4:16 pm

Macro para leer archivos cierra Openoffice

Mensaje por rttsl »

Buen día a todos, necesito su ayuda, estoy trabajando con un archivo que lee información de otros archivos, la idea es que el archivo navega en una carpeta y abre los archivos con la propiedad Hidden, luego lee cierta información y lo cierra, el problema es al cerrar con el método .close(true) cierra todos los archivos abiertos que tengo de openoffice, ya trate con un wait por 4000 y dejando abierto el archivo mientras leo otro y lo cierro despues, pero siempre causa el error, alguien podría ayudarme. desde ya gracias.
OpenOffice 4.1 Windows
Avatar de Usuario
fornelasa
Mensajes: 3268
Registrado: Jue Feb 17, 2011 8:30 pm
Ubicación: Estado de México, México.

Re: Macro para leer archivos cierra Openoffice

Mensaje por fornelasa »

rttsl, sugiero subir un archivo ejemplo y (sí fuese necesario) aclarar un poco más la consulta.
Saludos, Federico.
lo 6.2.0 | aoo 4.1.6 | win 7/10
¡Un aplauso para todos los que luchan por proteger y promover la Web abierta!
rttsl
Mensajes: 20
Registrado: Jue May 14, 2015 4:16 pm

Re: Macro para leer archivos cierra Openoffice

Mensaje por rttsl »

Que tal Federico, gracias por el tiempo, la macro lo que hace es que saca información de otros archivos en una carpeta, internamente abre el archivo, extrae la información y luego lo cierra, pero al cerrar el archivo, se cierran todos los libros abiertos, leí algo acerca de un problema con esto, que al cerrar un libro algunas veceses se cierran todos los libros, pero no estoy seguro.
OpenOffice 4.1 Windows
Avatar de Usuario
mauricio
Mensajes: 6092
Registrado: Sab Nov 22, 2008 5:36 am
Ubicación: CDMX
Contactar:

Re: Macro para leer archivos cierra Openoffice

Mensaje por mauricio »

Como ya te comentaron, sin ver, es difícil ayudarte.
______________________________________________
"Todo cuanto no podemos dar nos posee". - André Gide
LibreOffice 6.2 | ArchLinux | Gnome3
No respondo preguntas privadas, por favor, usa el foro
rttsl
Mensajes: 20
Registrado: Jue May 14, 2015 4:16 pm

Re: Macro para leer archivos cierra Openoffice

Mensaje por rttsl »

Si claro, este es lo que tengo, es una modificación de una macro que use para algo parecido, por eso hay algunas variables de más.

Código: Seleccionar todo

Sub Extraer 
' prueba opciones de carpeta raiz
'///////////////////////////////////////

Dim oSFA As Object
Dim mArchivos()
Dim tmp() as string
dim tmp1() as string
Dim archivo
Dim lArchivo As string
Dim directorio As string
'///// Arbir archivos
Dim oDoc As Object
Dim oDoc1 As Object
Dim sRuta As String
'/// Llenar datos
Dim oSel As Object
Dim oCursor As Object
Dim oHojaActiva As Object
Dim oCelda As Object
Dim oCelda2 As Object
Dim oCelda3 As Object
dim document   as object
dim dispatcher as object
dim C_EN as Integer
DIM F_i
DIM F_f
DIM F_A
On Error Resume next
'/// Navegar para encontrar la línea inicial
'Referencia a la hoja activa

oDoc1=thiscomponent
oHoja=oDoc1.sheets.getbyname("Consolidado")

thiscomponent.store()
oSFA = createUnoService("com.sun.star.ucb.SimpleFileAccess")
Directorio = ConvertToUrl ("X:\Gestiones Contables\Enero 2016\Día 5\")
If oSFA.isFolder(Directorio) Then
	mArchivos = oSFA.getFolderContents( Directorio, FALSE )
	For Each archivo In mArchivos
			if  Right(archivo,3)="ods" then
				oCelda = oHojaActiva.getCellByPosition( 1,a+1 )
				oCelda2 = oHojaActiva.getCellByPosition( 145,a+1 )
				oCelda3 = oHojaActiva.getCellByPosition( 146,a+1 )
				archivo1=convertfromurl(archivo)
				tmp = Split(archivo1,"/")
            	lArchivo = tmp(UBound(tmp))
				'BX=BUSQUEDAX(lArchivo,"Hoja1",thiscomponent,"X")
				'if BX = "N/D" THEN
				oDoc = AbrirArchivo(archivo,TRUE)
				oSel = oHoja.getCellbyposition(0,5)
				oCursor = oSel.getSpreadSheet.createCursorByRange( oSel )
				oCursor.gotoEnd()
				a=oCursor.getRangeAddress.EndRow
				if oDoc.getsheets().hasbyname("Consolidado") then 
					if oDoc.getsheets.getbyname("Consolidado").getcellbyposition(0,0).string="GC44" then
						oHojaActiva = oDoc.sheets.getbyname("Consolidado")
						b=4
						oSel = oHojaActiva.getCellbyposition(0,b)
						oCursor = oSel.getSpreadSheet.createCursorByRange( oSel )
						oCursor.gotoEnd()
						c=oCursor.getRangeAddress.EndRow

						for k=1 to (c-(b))
							oHoja.getcellbyposition(1,a+k).string=oHojaActiva.getcellbyposition(1,b+k).string
							oHoja.getcellbyposition(2,a+k).string=oHojaActiva.getcellbyposition(2,b+k).string
							oHoja.getcellbyposition(3,a+k).string=oHojaActiva.getcellbyposition(3,b+k).string
							oHoja.getcellbyposition(4,a+k).value=oHojaActiva.getcellbyposition(4,b+k).value
							oHoja.getcellbyposition(5,a+k).string=oHojaActiva.getcellbyposition(5,b+k).string
							oHoja.getcellbyposition(6,a+k).string=oHojaActiva.getcellbyposition(6,b+k).string
							oHoja.getcellbyposition(7,a+k).string=oDoc.getsheets.getbyname("Consolidado").getcellbyposition(1,0).string
							oHoja.getcellbyposition(8,a+k).string=oHojaActiva.getcellbyposition(7,b+k).string
							oHoja.getcellbyposition(0,a+k).string=a+k-4
						next k
					else
						if oDoc.getsheets.getbyname("Consolidado").getcellbyposition(0,0).string="GCG" then
						
							oHojaActiva1 = oDoc.sheets.getbyname("Gestiones")
							oSel = oHojaActiva1.getCellbyposition(0,1)
							oCursor = oSel.getSpreadSheet.createCursorByRange( oSel )
							oCursor.gotoEnd()
							d=oCursor.getRangeAddress.EndRow
							oHojaActiva=oDoc.getsheets.getbyindex(oDoc.getsheets.getcount-1)
							for L=1 to d
								b=busquedax(oHojaActiva1.getcellbyposition(0,L).string,oHojaActiva.getname,oDoc,"X")
								if b <> "N/D" then
									b=b+1
									oSel = oHojaActiva.getCellbyposition(0,b)
									oCursor = oSel.getSpreadSheet.createCursorByRange( oSel )
									oCursor.gotoEnd()
									c=oCursor.getRangeAddress.EndRow
									
									k1=1		
									for k=1 to (c-(b))
										if len(oHojaActiva.getcellbyposition(1,b+k).string)>0 then
											oHoja.getcellbyposition(1,a+k1).string=oHojaActiva.getcellbyposition(1,b+k).string
											oHoja.getcellbyposition(2,a+k1).string=oHojaActiva.getcellbyposition(2,b+k).string
											oHoja.getcellbyposition(3,a+k1).string=oHojaActiva.getcellbyposition(3,b+k).string
											oHoja.getcellbyposition(4,a+k1).value=oHojaActiva.getcellbyposition(4,b+k).value
											oHoja.getcellbyposition(5,a+k1).string=oHojaActiva.getcellbyposition(5,b+k).string
											oHoja.getcellbyposition(6,a+k1).string=oHojaActiva.getcellbyposition(6,b+k).string
											oHoja.getcellbyposition(7,a+k).string=oDoc.getsheets.getbyname("Consolidado").getcellbyposition(1,0).string
											oHoja.getcellbyposition(8,a+k).string=oHojaActiva1.getcellbyposition(0,L).string
											oHoja.getcellbyposition(0,a+k1).string=a+k-4
											k1=k1+1
										endif
									next k
									a=a+k1-1								
								Endif
							Next L		

						else
							oHojaActiva=oDoc.getsheets.getbyindex(oDoc.getsheets.getcount-1)
							b=8
							oSel = oHojaActiva.getCellbyposition(0,b)
							oCursor = oSel.getSpreadSheet.createCursorByRange( oSel )
							oCursor.gotoEnd()
							c=oCursor.getRangeAddress.EndRow
							for k=1 to (c-(b))
								oHoja.getcellbyposition(1,a+k).string=oHojaActiva.getcellbyposition(1,b+k).string
								oHoja.getcellbyposition(2,a+k).string=oHojaActiva.getcellbyposition(2,b+k).string
								oHoja.getcellbyposition(3,a+k).string=oHojaActiva.getcellbyposition(3,b+k).string
								oHoja.getcellbyposition(4,a+k).value=oHojaActiva.getcellbyposition(4,b+k).value
								oHoja.getcellbyposition(5,a+k).string=oHojaActiva.getcellbyposition(5,b+k).string
								oHoja.getcellbyposition(6,a+k).string=oHojaActiva.getcellbyposition(6,b+k).string
								oHoja.getcellbyposition(7,a+k).string=oDoc.getsheets.getbyname("Consolidado").getcellbyposition(1,0).string
								oHoja.getcellbyposition(0,a+k).string=a+k-4
							next k
						endif
					endif
				Endif
				oDoc.Close(true)
				'End if
			end if
		'End if   'revisor de fecha.
	Next
End If
   

end sub



Function AbrirArchivo( Ruta As String, Oculto As Boolean ) As Object
Dim sRuta As String
Dim mOpc(1) As New "com.sun.star.beans.PropertyValue"

   mOpc(0).Name = "Hidden"
   mOpc(0).Value = True
   mOpc(1).Name = "MacroExecutionMode"
   mOpc(1).Value = 4
   sRuta = converttourl(Ruta)
   AbrirArchivo = StarDesktop.loadComponentFromURL( sRuta, "_blank", 0, mOpc() )

End Function
He colocado algunas banderas para validar, y es en el cierre. con el .close(true)
OpenOffice 4.1 Windows
Avatar de Usuario
mauricio
Mensajes: 6092
Registrado: Sab Nov 22, 2008 5:36 am
Ubicación: CDMX
Contactar:

Re: Macro para leer archivos cierra Openoffice

Mensaje por mauricio »

El primer error que veo, si esto es todo tu código. La primer referencia que haces a "oHojaActiva", no se ve donde le asignes un valor, esa línea debería darte un error.

Por otra parte, todo eso largo y tedioso código, lo puedes convertir en unas cuantas limpias y claras líneas con easy-macro, si lo puedes usar te ayudo a traducirlo a Python.

Saludos
______________________________________________
"Todo cuanto no podemos dar nos posee". - André Gide
LibreOffice 6.2 | ArchLinux | Gnome3
No respondo preguntas privadas, por favor, usa el foro
rttsl
Mensajes: 20
Registrado: Jue May 14, 2015 4:16 pm

Re: Macro para leer archivos cierra Openoffice

Mensaje por rttsl »

No, no sabía de easy-macro, pero me gustaría aprender, la verdad si fue bastante tedioso hacerlo, si agregue valor a oHojaActiva, la macro si corre, y extrae algunos registro, luego de eso se cierra repentinamente la aplicación, y me pide recuperar los archivos cerrados.
OpenOffice 4.1 Windows
Avatar de Usuario
mauricio
Mensajes: 6092
Registrado: Sab Nov 22, 2008 5:36 am
Ubicación: CDMX
Contactar:

Re: Macro para leer archivos cierra Openoffice

Mensaje por mauricio »

Si puedes instalar y ejecutar la macro de prueba: https://forum.openoffice.org/es/forum/v ... 50&t=13062

entonces podemos continuar...
______________________________________________
"Todo cuanto no podemos dar nos posee". - André Gide
LibreOffice 6.2 | ArchLinux | Gnome3
No respondo preguntas privadas, por favor, usa el foro
Responder