Das Notes Forum
Domino 9 und frühere Versionen => ND6: Entwicklung => Thema gestartet von: Christoph.1982 am 10.10.06 - 16:05:09
-
Hallo,
ich habe folgenden vorliegenden Programmcode in meinem Notes der die Daten in ein Excel Spreasheet exportiert. Es funktioniert auch, aber ich haette noch ein paar fragen dazu:
Vielen herzlichen Dank fuer eure Antworten.
Viele Gruesse Chris
Sub Click(Source As Button)
Dim s As New NotesSession
Dim View As NotesView
Dim EC As NotesViewEntryCollection
Dim vE As NotesViewEntry
Dim n As Long
Dim Row As Long
Dim xlApp As Variant
Dim xlWB As Variant
Dim xlSheet As Variant
Dim column As NotesViewColumn
Dim i As Integer
On Error Goto Error_Export
Set View = s.CurrentDatabase.getView("Phone Log / ServiceFollowUp")
If Not(View Is Nothing) Then Was ist das Nothing? Ist habe mir gedacht, wenn in de Ansicht View nichts ist und dies ist nochmal negiert mit dem not --> Also muss was in dem View sein, damit er weitermacht, ist das richtig?
Set xlApp = createobject("Excel.Application")
xlApp.DisplayAlerts = False
xlApp.Visible = False
Set xlWB = xlApp.WorkBooks.Add
Set xlSheet = xlWB.Sheets(1)
xlSheet.Name = "MainData"
' write the columnnames
Row = 1
For i = 0 To view.ColumnCount -1
Set column = view.Columns(i)
xlSheet.Cells(Row, i +1) = column.ItemName
Next
' format the columnnames (grey and bold)
xlSheet.Range("A1:AW1").Interior.ColorIndex = 15
xlSheet.Range("A1:AW1").Font.Bold = True
' write the rows
Set EC = View.AllEntries
Set vE =EC.getFirstEntry getFirstEntry? was ist der erste Eintrag in dem View? Erste Spalte und Erste Zeile?
While Not(vE Is Nothing) Wieder gleicher Fall wie oben?
If vE.IsDocument Then
Row = Row + 1 In dieser Schleife habe ich die For Anweisung verstanden, aber die zaehlt doch nur die columns hoch, ich weiss aber leider nicht wie er hier die Rows hochzaehlt, bzw wie das funktioniert, weil oben steht ja Row=Row+1, aber das steht doch in keiner Schleife das es hochzaehlen koennte, oder?
' not the last row
For n = 0 To Ubound(vE.ColumnValues)
xlSheet.Cells(Row, n + 1) = vE.ColumnValues(n) ' to prevent excel errors
Next
End If
Set vE = EC.getNextEntry(vE)
Wend
End If
Call xlWB.SaveAs("C:\PhoneLogServiceFollowUp.xls")
Call xlWB.Close
Call xlApp.Quit
Messagebox "Export successful to C:\PhoneLogServiceFollowUp.xls! Pleae open your Excel file InformationQuotes.xls and update your data.", 64, "Information"
Error_Export:
If (Err <> 0) Then Und das versteh ich auch nicht...Was ist Err, oben ist das doch nirgends als Variable deklariert...und was soll das Aussagen Err<>0?
Messagebox Error$, 48, "An error has occurred..."
End If
Exit Sub
End Sub
-
Also muss was in dem View sein, damit er weitermacht, ist das richtig?
Richtig, View muss vorhanden sein. Mit GetFirstDocument wird gelesen.
getFirstEntry? was ist der erste Eintrag in dem View?
Erstes Dokument
For n = 0 To Ubound(vE.ColumnValues)
Hier wird hochgezählt.
oben ist das doch nirgends als Variable deklariert
Muss man auch nicht unbedingt. Dann legt LoNo autom einen Variant-Wert an.
Am besten lässt Du mal den Debugger mitlaufen. Da sieht man vieles viel schöner.
-
st habe mir gedacht, wenn in de Ansicht View nichts ist und dies ist nochmal negiert mit dem not --> Also muss was in dem View sein, damit er weitermacht, ist das richtig?
Die Frage ist nicht eindeutig genug formuliert. Das View-Objekt muß vorhanden sein. Das ist keine Überprüfung, ob sich Dokumente in der View befinden.
-
oben ist das doch nirgends als Variable deklariert
Muss man auch nicht unbedingt. Dann legt LoNo autom einen Variant-Wert an.
Err ist keine Variable, sondern die Notes-interne Function, die die aktuelle Fehlernummer zurückgibt.
Bernhard
-
Err ist keine Variable, sondern die Notes-interne Function
Asche auf mein Haupt, schneller geschrieben als gedacht.... :'(
-
Zitat
For n = 0 To Ubound(vE.ColumnValues)
Hier wird hochgezählt.
Aber da wird doch nur die Columns hochgezaehlt...und wo werden die rows hochgezaehlt?
-
Da haett ich noch ne Frage, dann versteh ich das auch besser mit den rows...in dem view sind 5000 rows und wenn ich da jetzt nur die ersten 100 in excel haben moechte was muesste ich dann oben in dem Programm Code aendern?
Viele Gruesse Chris
-
Die Abbruchbedinung für die While-Schleife, in der er die Zeilen durchgeht anpassen.
Kann es sein, dass Du noch nicht wirklich viel Coding-Erfahrung hast? Was sagt Dein Mentor/Ausbildner/Chef? Kannst Du den nicht fragen?
-
Hallo, hat sich erledigt...habs hinbekommen :)
ne, also von programmieren hab ich nicht soviel Ahnung, da ich Maschinenbau Student bin...aber ich mache gerade ein Praktika und da muss ich mit LotusNotes arbeiten...
Viele Gruesse Chris
Hier der fuktionierende Code:
Sub Click(Source As Button)
Dim s As New NotesSession
Dim View As NotesView
Dim EC As NotesViewEntryCollection
Dim vE As NotesViewEntry
Dim n As Long
Dim Row As Long
Dim xlApp As Variant
Dim xlWB As Variant
Dim xlSheet As Variant
Dim column As NotesViewColumn
Dim i As Integer
On Error Goto Error_Export
Set View = s.CurrentDatabase.getView("Phone Log / ServiceFollowUp")
If Not(View Is Nothing) Then
Set xlApp = createobject("Excel.Application")
xlApp.StatusBar = "Create WorkSheet. Please wait."
xlApp.DisplayAlerts = False
xlApp.Visible = True
Set xlWB = xlApp.WorkBooks.Add
Set xlSheet = xlWB.Sheets(1)
xlSheet.Name = "MainData"
' write the columnnames
Row = 1
For i = 0 To view.ColumnCount -1
Set column = view.Columns(i)
xlSheet.Cells(Row, i +1) = column.ItemName
Next
' format the columnnames (grey and bold)
xlSheet.Range("A1:AW1").Interior.ColorIndex = 15
xlSheet.Range("A1:AW1").Font.Bold = True
' write the rows
Set EC = View.AllEntries
Set vE =EC.getFirstEntry
Row=0
While (Row <=100)
If vE.IsDocument Then
Row = Row + 1
' not the last row
For n = 0 To Ubound(vE.ColumnValues)
xlSheet.Cells(Row, n + 1) = vE.ColumnValues(n) ' to prevent excel errors
Next
xlApp.StatusBar = "Importing Notes Data"
End If
Set vE = EC.getNextEntry(vE)
Wend
End If
xlApp.Cells.Select
xlApp.Selection.Columns.AutoFit
xlApp.Selection.Rows.AutoFit
xlApp.Range("A1").Select
Call xlWB.SaveAs("C:\PhoneLogServiceFollowUp.xls")
Call xlWB.Close
Call xlApp.Quit
Messagebox "Export successful to C:\PhoneLogServiceFollowUp.xls!", 64, "Information"
Error_Export:
If (Err <> 0) Then
Messagebox Error$, 48, "An error has occurred..."
End If
Exit Sub
End Sub