Domino 9 und frühere Versionen > Entwicklung
Excel 2 Notes
bob:
Hi,
ich habe eine Ansicht mit folgenden Spalten:
Kostenstelle | KSt-Bezeichnung | Verantwortlicher
Nun würde ich gerne einen Button einbauen, beim Klick darauf soll:
- eine Dateiauswahl kommen, um ein Excel-File auszuwählen
- Die Zeilen 2 bis zur letzten sollen ausgelesen werden
- Die Daten ins Notes importiert werden, dabei die Maske "frm_Kst" verwenden
Manuell (über Menü Datei / importieren) klappt das ja super, aber hat da vielleicht wer von Euch eine Skript-Lösung, um es dem AW noch mehr zu vereinfachen?
Wäre schön, wenn ein Excel-File ausgewählt werden könnte, aber .wk4 würde auch reichen.
Außerdem schön wäre, wenn der Anwender im Excel in die 1. Zeile nicht die exakten Feldnamen schreiben muss.....
bye,
Bob
Rob Green:
aktiviere bitte die Forumsuche, gebe Excel ein (evtl. noch dazu Import / Export / ...) udn Suchzeitraum 270 Tage. Oder: auf www.eknori.de gehen und dort suchen. Oder auf der Lotus Homepage in der Sandbox. Excel ist ein beliebtes Thema für Im/Export Lösungen.
ata:
... Excel per ODBC habe ich als skizziertes Beispiel in meinem LotusScript-Teil unter "Datenbanken"
http://www.anton-tauscher.de
... => LotusScript-Kurs => Datenbanken
ata
bob:
Hi,
danke für Eure Tipps.
In atnotes hatte ich nicht richtig was gefunden, daher mein Posting.
Aber die Sandbox hat was :-)
Excel
Der Code ist auch ganz gut und funzt soweit, ich habe noch ergänzt/geändert, dass man mit einem Filerequester ein Excel-File auswählt. Außerdem hab ich meine View und meine Maske gleich fix eingebaut.
Allerdings muss in der ersten Zeile im Excel der jew. Feldname stehen, sonst gehts ned.
Des weiteren übernimmt das Skript auch die erste Zeile, was keinen Sinn macht (es erstellt also auch ein Dokument, wo es z.B. in den Feldnamen KSt_Bezeichnung" reinschreibt "KSt_Bezeichnung".
Ich würde dem Script daher gerne die Feldnamen "KSt_KSt", "KSt_Bezeichnung" und "KSt_Verantwortung" gerne vorgeben, und dann dem Script beibringen, dass es die Werte erst ab Zeile 2 übernimmt.
Allerdings weiss ich nicht exakt wie:
Sub Initialize
'********************************** Excel -> Notes by Bob *****************************
'Quelle: Lotus Sandbox, ursprüngliche Version: revision ver 2 -30/11/02
'Letzte Änderung: 08.06.2003 (Bob)
'*********************************************************************************************************
' importing into a notes database excel specified files in specified view and form.
' default Ansicht: "VKostenstellen"
' default Maske: "frm_Kostenstellen"
' default sw version w2000
Dim session As New NotesSession
Dim db As NotesDatabase
Dim view As NotesView
Dim doc As NotesDocument
Set db = session.CurrentDatabase
Set doc = New NotesDocument(db)
Dim item As NotesItem
Dim One As String
Dim row As Integer
Dim written, records,ver As Integer
Dim FName As String
Dim VName As String
Dim xlFilename As String
'Start Dims etc. für Fileauswahl
Dim workspace As New NotesUIWorkspace
Dim files As Variant
'Ende Dims etc. für Fileauswahl
On Error Goto Error_call
'************** Start Fileauswahl *********
files = workspace.OpenFileDialog(True, "Wählen Sie eine Excel-Datei aus:", _
"Excel-Dateien (*.xls)|*.xls|Alle Dateien|*", "c:")
Forall filelist In files
xlFilename = xlFilename & filelist
End Forall
'Messagebox xlFilename
'************** Ende Fileauswahl *********
' Row number to import
ans$ = Inputbox$("How many rows to import ? ","Info","10")
If ans$ = "" Then
records= "10" ' This is the default import row number
Else
records = ans$ ' This is the user import row number
End If
' Version
ans$ = Inputbox$("Are you using W2000 ? ","Info","Y")
If ans$ = "n" Or ans$ = "N" Then
ver= 8
Else
ver=9
End If
' View name
Set view = db.GetView("VKostenstellen") ' This is the default View name
' Form name
FormName= "frm_Kostenstellen" ' This is the default form name
'Next we connect to Excel and open the file. Then start pulling over the records.
Dim Excel As Variant
Dim xlWorkbook As Variant
Dim xlSheet As Variant
Print "Connecting to Excel..."
If ver =9 Then
Set Excel = CreateObject( "Excel.Application.9" ) ' for windows2000
Else
Set Excel = CreateObject( "Excel.Application.8" ) ' for windows95
End If
'Excel.Visible = False ' Don't display the Excel window
Print "Opening " & xlFilename & "..."
Excel.Workbooks.Open xlFilename ' Open the Excel file
Set xlWorkbook = Excel.ActiveWorkbook
Set xlSheet = xlWorkbook.ActiveSheet
' Cycle through the rows of the Excel file, pulling the data over to Notes
Goto Records
Print "Disconnecting from Excel..."
xlWorkbook.Close False 'Close the Excel file without saving (we made no changes)
Excel.Quit 'Close Excel
Set Excel = Nothing ' Free the memory that we'd used
Print " " ' Clear the status line
Records:
row = 0 'These integers intialize to zero anyway
written = 0
Print "Starting import from Excel file..."
Do While True
Finish:
With xlSheet
row = row + 1
' field definitions
If row=1 Then
temp1=.Cells( row, 1 ).Value
temp2=.Cells( row, 2 ).Value
temp3=.Cells( row, 3 ).Value
temp4=.Cells( row, 4 ).Value
temp5=.Cells( row, 5 ).Value
temp6=.Cells( row, 6 ).Value
temp7=.Cells( row, 7 ).Value
temp8=.Cells( row, 8 ).Value
temp9=.Cells( row, 9 ).Value
temp10=.Cells( row, 10 ).Value
temp11=.Cells( row, 11 ).Value
temp12=.Cells( row, 12 ).Value
temp13=.Cells( row, 13).Value
temp14=.Cells( row, 14).Value
temp15=.Cells( row, 15 ).Value
temp16=.Cells( row, 16 ).Value
temp17=.Cells( row, 17 ).Value
temp18=.Cells( row, 18 ).Value
temp19=.Cells( row, 19 ).Value
temp20=.Cells( row, 20 ).Value
temp21=.Cells( row, 21 ).Value
temp22=.Cells( row, 22 ).Value
temp23=.Cells( row, 23 ).Value
temp24=.Cells( row, 24 ).Value
temp25=.Cells( row, 25 ).Value
temp26=.Cells( row, 26 ).Value
temp27=.Cells( row, 27 ).Value
temp28=.Cells( row, 28 ).Value
temp29=.Cells( row, 29 ).Value
temp30=.Cells( row, 30 ).Value
temp31=.Cells( row, 31 ).Value
temp32=.Cells( row, 32 ).Value
temp33=.Cells( row, 33 ).Value
temp34=.Cells( row, 34 ).Value
temp35=.Cells( row, 35 ).Value
temp36=.Cells( row, 36 ).Value
temp37=.Cells( row, 37 ).Value
temp38=.Cells( row, 38 ).Value
temp39=.Cells( row, 39 ).Value
temp40=.Cells( row, 40 ).Value
temp41=.Cells( row, 41 ).Value
temp42=.Cells( row, 42 ).Value
temp43=.Cells( row, 43 ).Value
temp44=.Cells( row, 44 ).Value
temp45=.Cells( row, 45 ).Value
temp46=.Cells( row, 46 ).Value
temp47=.Cells( row, 47 ).Value
temp48=.Cells( row, 48 ).Value
temp49=.Cells( row, 49 ).Value
temp50=.Cells( row, 50 ).Value
temp51=.Cells( row, 51 ).Value
temp52=.Cells( row, 52 ).Value
temp53=.Cells( row, 53 ).Value
temp54=.Cells( row, 54 ).Value
temp55=.Cells( row, 55 ).Value
temp56=.Cells( row, 56 ).Value
temp57=.Cells( row, 57 ).Value
temp58=.Cells( row, 58 ).Value
temp59=.Cells( row, 59 ).Value
temp60=.Cells( row, 60 ).Value
temp61=.Cells( row, 61 ).Value
temp62=.Cells( row, 62 ).Value
temp63=.Cells( row, 63 ).Value
temp64=.Cells( row, 64 ).Value
temp65=.Cells( row, 65 ).Value
temp66=.Cells( row, 66 ).Value
temp67=.Cells( row, 67 ).Value
temp68=.Cells( row, 68 ).Value
temp69=.Cells( row, 69 ).Value
temp70=.Cells( row, 70 ).Value
temp71=.Cells( row, 71 ).Value
temp72=.Cells( row, 72 ).Value
temp73=.Cells( row, 73 ).Value
temp74=.Cells( row, 74 ).Value
temp75=.Cells( row, 75 ).Value
temp76=.Cells( row, 76 ).Value
temp77=.Cells( row, 77 ).Value
temp78=.Cells( row, 78 ).Value
temp79=.Cells( row, 79 ).Value
temp80=.Cells( row, 80 ).Value
temp81=.Cells( row, 81 ).Value
temp82=.Cells( row, 82 ).Value
temp83=.Cells( row, 83 ).Value
temp84=.Cells( row, 84 ).Value
temp85=.Cells( row, 85 ).Value
temp86=.Cells( row, 86 ).Value
temp87=.Cells( row, 87 ).Value
temp88=.Cells( row, 88 ).Value
temp89=.Cells( row, 89 ).Value
temp90=.Cells( row, 90 ).Value
temp91=.Cells( row, 91 ).Value
temp92=.Cells( row, 92 ).Value
temp93=.Cells( row, 93 ).Value
temp94=.Cells( row, 94 ).Value
temp95=.Cells( row, 95 ).Value
temp96=.Cells( row, 96 ).Value
temp97=.Cells( row, 97 ).Value
temp98=.Cells( row, 98 ).Value
temp99=.Cells( row, 99 ).Value
temp100=.Cells( row, 100 ).Value
End If
' end field definition
' Set view = db.GetView
Set doc = db.CreateDocument 'Create a new doc
doc.Form = FormName
'...set value of doc...
Set item = doc.ReplaceItemValue( temp1, .Cells( row, 1 ).Value )
Set item = doc.ReplaceItemValue( temp2, .Cells( row, 2 ).Value )
Set item = doc.ReplaceItemValue( temp3, .Cells( row, 3 ).Value )
Call doc.Save( True, True ) 'Save the new doc
written = written + 1
Print Str(written)
If written =Int(records) Then
Goto Done
End If
End With
Loop
Return
Goto Done
Error_call:
Messagebox "Check Excel file location or SW Version or View Name or Form Name" ,MB_OK+MB_ICONINFORMATION,"Warning ! "
Print " " ' Clear the status line
Exit Sub
Done:
Excel.Quit 'Close Excel
Set Excel = Nothing ' Free the memory that we'd used
Print "Imported " +Cstr(row) + " rows" ' Clear the status line
End Sub
Hat wer von Euch eine Idee?
Bob
Axel_Janssen:
ohne das ich zeit hätte mich da jetzt länger mit zu beschäftigen, aber
es hängt mit diesen Zeilen zusammen (bin mir ziemlich sicher):
--- Code: ---Set item = doc.ReplaceItemValue( temp1, .Cells( row, 1 ).Value )
Set item = doc.ReplaceItemValue( temp2, .Cells( row, 2 ).Value )
Set item = doc.ReplaceItemValue( temp3, .Cells( row, 3 ).Value )
--- Ende Code ---
versuch da mal temp1, temp2, temp3 mit den hartkodierten Feldnamen zu ersetzen.
Navigation
[0] Themen-Index
[#] Nächste Seite
Zur normalen Ansicht wechseln