Un agente que crea un informe utilizando excel
Sub Initialize
'--------------------------------------- (02/04/2001) ------ Informes
en Excel ----------------------------------------------------------------
Dim ns As New NotesSession
Dim ndb As NotesDatabase
Dim nview As notesview
Dim nd As notesdocument
Dim Excel As Variant
Dim xlWorkbook As Variant
Dim xHoja As Variant
Set ndb = ns.CurrentDatabase
mes = Inputbox$("Introduzca el Mes por el cual desea generar el
informe. (ej.: enero)","Introduzca el mes")
mes2 = mes
'------------------------------------- Convertimos el mes para la
exportación
-----------------------------------------------------------------
convertir:
If mes = "enero" Then
mes=1
Elseif mes = "febrero" Then
mes=2
Elseif mes = "marzo" Then
mes=3
Elseif mes = "abril" Then
mes=4
Elseif mes = "mayo" Then
mes=5
Elseif mes = "junio" Then
mes=6
Elseif mes = "julio" Then
mes=7
Elseif mes = "agosto" Then
mes=8
Elseif mes = "septiembre" Then
mes=9
Elseif mes = "octubre" Then
mes=10
Elseif mes = "noviembre" Then
mes=11
Elseif mes = "diciembre" Then
mes=12
Else
Msgbox("Recuerde que el mes debe escribirlo en minusculas (ej.:
enero)")
mes = Inputbox$("Introduzca el Mes por el cual desea generar el
informe. (ej.: enero)","Introduzca el mes")
Goto convertir
End If
Set nview=ndb.getview("vInformeMes")
Set nd = nview.GetFirstDocument
If nd Is Nothing Then
Beep
Msgbox("No se han encontrado documentos del mes solicitado")
Exit Sub
Else
Goto continuar
End If
fecha=Month(nd.fchComienzoBaja(0))
doc = 0
If fecha = mes Then
doc = doc + 1
Set nd = nview.GetNextDocument(nd)
Else
Set nd = nview.GetNextDocument(nd)
End If
If doc = 0 Then
Beep
Msgbox("No se han encontrado documentos del mes solicitado")
Exit Sub
Else
Goto continuar
End If
continuar:
Set nd = nview.GetFirstDocument
Print "Iniciando la creación de Informe..."
Print "Conectando con EXCEL..."
Set Excel = CreateObject( "Excel.Application" )
Excel.Visible = True '// Mostramos la ventana de Excel
Excel.Workbooks.Add '//Creamos un libro de Excel nuevo
Set xlWorkbook = Excel.ActiveWorkbook '//Seleccionamos el libro activo
row = 0 '//Inicializamos las columnas a 0
documento = 0
Print "Iniciando la creación del Informe..."
While Not (nd Is Nothing)
row = row + 1
documento = documento + 1
If row = 1 Then
'//Introducimos el
titulo-----------------------------------------------------------------
Excel.Cells(row,1).Value = "Informe documentos aprobados
cuyo periodo corresponde al mes de " & mes2
Excel.Selection.Font.Bold = True
Excel.Selection.Font.Italic = True
Excel.Selection.Interior.ColorIndex = 15
Excel.Selection.Font.Size = 13
Excel.Range("A1:F1").Select
Excel.Selection.Merge
Elseif row = 2 Then
'//Introducimos las
cabeceras--------------------------------------------------------------
Excel.Cells(row,1).Value="Nº Empleado"
Excel.Cells(row,1).Select
Excel.Selection.Font.Bold = True
Excel.Selection.Font.Size = 11
Excel.Cells(row,2).Value="Nombre Empleado"
Excel.Cells(row,2).Select
Excel.Selection.Font.Bold = True
Excel.Selection.Font.Size = 11
Excel.Cells(row,3).Value="Motivo Ausencia"
Excel.Cells(row,3).Select
Excel.Selection.Font.Bold = True
Excel.Selection.Font.Size = 11
Excel.Cells(row,4).Value="Comienzo"
Excel.Cells(row,4).Select
Excel.Selection.Font.Bold = True
Excel.Selection.Font.Size = 11
Excel.Cells(row,5).Value="Incorporación"
Excel.Cells(row,5).Select
Excel.Selection.Font.Bold = True
Excel.Selection.Font.Size = 11
Excel.Cells(row,6).Value="Duración"
Excel.Cells(row,6).Select
Excel.Selection.Font.Bold = True
Excel.Selection.Font.Size = 11
Else
motivo = nd.cEnfermedadBaja(0)
If motivo = "OTROS" Then
motivo = "OTROS: " & nd.tMotivo(0)
Else
motivo = nd.cEnfermedadBaja(0)
End If
'//Introducimos los
valores--------------------------------------------------------------------
Excel.Cells(row,1).Value=nd.tNEmpleado(0)
Excel.Cells(row,2).Value=nd.tNombre(0)
Excel.Cells(row,3).Value= motivo
Excel.Cells(row,4).Value=nd.fchComienzoBaja(0)
Excel.Cells(row,5).Value=nd.fchIncorporacionTrabajo(0)
Excel.Cells(row,6).Value=nd.tNDuracion(0)
Set nd = nview.GetNextDocument(nd)
End If
Wend
'//Autoajustamos las
columnas------------------------------------------------------------------------
Excel.Columns("A:A").EntireColumn.AutoFit
Excel.Columns("B:B").EntireColumn.AutoFit
Excel.Columns("C:C").EntireColumn.AutoFit
Excel.Columns("D:D").EntireColumn.AutoFit
Excel.Columns("E:E").EntireColumn.AutoFit
Excel.Columns("F:F").EntireColumn.AutoFit
Print "Se han exportado datos de "&documento" documentos"
Print "Finalizada la creación del informe..."
End Sub
|
Otros documentos de LotusScript
|