- Defino variables globales para cada documento:
Public docMacros, DocTodos, DocMatricula, DocNiveles, DocMaterias as object
- Después los abro con la siguiente rutina:
DocMatricula=AbreDoc("matricula.ods")
DocNiveles=AbreDoc("niveles.ods")
DocMaterias=AbreDoc("materias.ods")
function AbreDoc(doc as string)
dim i as integer
dim lExiste as boolean
dim urlDoc
dim Dummy()
UrlDoc =url+doc
'Genera una lista de domumentos abiertos en la matriz NombreDocumentos
ListaDocumentos
'Comprueba si ya está abierto
for i=0 to UBound( NombreDocumentos() )
lExiste=(doc=NombreDocumentos(i))
if lExiste then
AbreDoc=aDocumentos(i)
exit function
end if
next
' Si no está abierto lo abre
if not lExiste then
AbreDoc=StarDesktop.LoadComponentFromURL(urlDoc,doc,0,Dummy())
end if
end function
- Luego accedo del modo siguiente:
....
hojaOrigen=docMatricula.sheets(0)
hojaDestino=docTodos.sheets(0)
....
...
aRegistro(12)=hojaOrigen.getCellByposition(1,fila).string
aRegistro(13)=hojaOrigen.getCellByposition(2,fila).string
aRegistro(14)=hojaOrigen.getCellByposition(3,fila).string
...
...
...
for i=0 to UBound( aRegistro() )
hojaDestino.getCellByposition(i,fila).string=aRegistro(i)
next
Sub Actualizar_Base
Dim oHoja As Object
Dim oCelda As Object
'Hacemos una referencia a la hoja activa
oHoja = ThisComponent.getCurrentController.getActiveSheet()
Dim Col As Long
Dim Fil As Long
dim nombre as string
dim primerparcial as string
dim final as string
dim ejerciciosclase as string
dim notrafinal1 as string
dim actitud as string
dim notafinal as string
Dim oDBC As Object
Dim oBD As Object
Dim oConexion As Object
Dim oDeclaracion As Object
Dim sBaseDatos As String
Dim sSQL As String
dim URL
URL=thisComponent.URL
url=Mid(URL,1,len(URL)-9)
'
sBaseDatos=url+ "curso.odb"
col=0
fil=5
dim i as integer
dim j as integer
'aqui se declara la base y se abre
'se hace que se pueda leer el primer registro
j=2
for i=fil to fil+41
oCelda = oHoja.getCellByPosition( Col,i )
nombre=oCelda.getString()
if len(nombre)=0 then
exit for
end if
oCelda = oHoja.getCellByPosition( Col+1,i )
primerparcial=oCelda.getString()
if len(primerparcial)=0 then
primerparcial=""
end if
oCelda = oHoja.getCellByPosition( Col+2,i )
final=oCelda.getString()
if len(final)=0 then
final=""
end if
oCelda = oHoja.getCellByPosition( Col+3,i )
ejerciciosclase=oCelda.getString()
if len(ejerciciosclase)=0 then
ejerciciosclase=""
end if
oCelda = oHoja.getCellByPosition( Col+4,i )
notafinal1=oCelda.getString()
if len(notafinal1)=0 then
notafinal1=""
end if
oCelda = oHoja.getCellByPosition( Col+5,i )
actitud=oCelda.getString()
if len(actitud)=0 then
actitud=""
end if
oCelda = oHoja.getCellByPosition( Col+6,i )
notafinal=oCelda.getString()
if len(notafinal)=0 then
notafinal=""
end if
sSQL = "UPDATE ""simix1"" SET ""NOMBRE""='" & nombre & "'," & """primerparcial""" & "='" & primerparcial & "'," & """final""" & "='" & final & "'," & """ejerciciosclase""" & "='" & ejerciciosclase & "'," & """notafinal1""" & "='" & notafinal1 & "'," & """actitud""" & "='" & actitud & "'," & """notafinal""" & "='" & notafinal & "' WHERE ""ID""=" & j &""
oDBC = createUnoService("com.sun.star.sdb.DatabaseContext")
oBD = oDBC.getByName(sBaseDatos)
oConexion = oBD.getConnection("","")
oDeclaracion = oConexion.createStatement()
oDeclaracion.executeUpdate( sSQL)
'luego se pasa al siguiente registro
'y luego se cierra la base
j=j+1
next i
oDeclaracion.close()
oConexion.close()
oDeclaracion = Nothing
oConexion = Nothing
End Sub
Usuarios navegando por este Foro: No hay usuarios registrados visitando el Foro y 2 invitados