Hallo Christopher,
hab dir hier mal was aus unserer Adressdatenbank kopiert. Ich benutze das Script, um unsere Adressen zu exportieren, damit unsere amerikanischen Kollegen die Daten in Groupwise übernehmen können.
Der Code exportiert alle Dokumente. Kannst du abre leicht umbauen, wenn du eine NotesDocumentCollection (unprocessed Documents ) statt eies View verwendest.
Der Code enthält die Klasse Fileguard, der dafür sorgt, dass die Ausgabedatei immer schön geschlossen wird, auch wenn der Code mal auf einen Fehler läuft oder Notes abschmiert.
'Export_STRATTEC:
'=====================================
' C L A S S "FileGuard"
'=====================================
'The specific example is a "FileGuard" class that guarantees that a file you open gets closed, no matter what else happens.
' How it works: whenever you declare a class in LotusScript, you can define a Delete method that executes
' when an object of that class is deallocated. This happens whenever the memory is freed, whether it's
' because the object has gone out of scope from the function it was declared in, or because the script aborted
' with an error, or by Ctrl+Break.
' The simple class below is useful when doing file I/O to make sure that you don't leave a file open if the user aborts.
' Note: you must open a file using the returned file handle from the Handle method, before you allocate
' another instance of FileGuard, or else they will get the same file number. Since Freefile returns the number
' of the first file handle that's not yet in use, calling it twice without using the result of the first call to open a
' file, returns the same value again.
Class FileGuard
filenumber As Integer
isopen As Integer
Public Property Get Handle
Handle = filenumber
End Property
Sub New()
filenumber = Freefile( )
isopen = True
End Sub
Sub Close
If isopen Then
On Error Resume Next
Close filenumber
isopen = False
End If
End Sub
Sub Delete
Me.Close
End Sub
End Class
Sub Click(Source As Button)
Dim s As New NotesSession
Dim db As NotesDatabase
Dim doc As NotesDocument
Dim View As NotesView
Dim Item As NotesItem
Dim outString As String
Dim i As Integer
' Keep the next three statements together
Dim FG1 As New FileGuard
outfile% = FG1.Handle
Open "D:\TEMP\STRATTEC.TXT" For Output As outfile%
Set db = s.CurrentDatabase
Set view = db.GetView ("(PicklistPersons)")
Set doc = View.GetFirstDocument
i = 1
outstring = Chr$(34) + "ID" +Chr$(34) + "," + Chr$(34) + "Name" +Chr$(34) + "," + Chr$(34) + "E-Mail Address" +Chr$(34) + "," + Chr$(34) + "First Name" +Chr$(34) + "," + Chr$(34) + "Last Name"
Print #outfile%, outString
While Not ( doc Is Nothing )
'// Read field values from document
Set Item = doc.GetFirstItem ("FirstNameOS")
FirstName$ = Item.Text
Set Item = doc.GetFirstItem ("LastNameOS")
LastName$ = Item.Text
If doc.hasItem ("InternetAddress") Then
Set Item = doc.GetFirstItem ("InternetAddress")
MailAddress$ = Item.Text
Else
MailAddress$ = ""
End If
Set Item = doc.GetFirstItem ("OfficePhoneNumber")
OfficePhoneNumber$ = Item.Text
Set Item = doc.GetFirstItem ("Department")
Department$ = Item.Text
'// Build outString
'// "ID","Name","E-Mail Address","First Name","Last Name"
outstring = Cstr(i) + ", " + Chr$(34) + LastName$ + ", " + FirstName$ + Chr$(34) + ", " +_
Chr$(34 ) + MailAddress$ + Chr$(34) + ", " +_
Chr$(34 ) + FirstName$ + Chr$(34) + ", " +_
Chr$(34 ) + LastName$ + Chr$(34)
' + ", " +_
'Chr$(34 ) + OfficePhoneNumber$ + Chr$(34) + ", " +_
'Chr$(34 ) + Department$ + Chr$(34)
Print #outfile%, outString
Print outstring
i = i +1
outString = ""
Set doc = view.GetNextDocument(doc)
Wend
FG1.Close
End Sub
Sollte dir als Grundlage für deine eigene Exportfunktion reichen.
@LUna: Sorry, aber nicht besonders LS Anfänger geeignet
eknori