Domino 9 und frühere Versionen > Entwicklung
Excel 2 Notes
Axel_Janssen:
und nochwas...
... im Grunde willst du aus dem bestehenden code Flexibilität herausnehmen, um in besser an deine konkretes Problem anzupassen. Das ist einfacher als umgekehrt.
Diese im Grunde pragmatische aber unschöne VB-Antwort auf introspection brauchst du nicht.
--- Code: --- 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
--- Ende Code ---
Du willst doch nur 3 Felder.
Also dürfte alles was hinter temp3 ist sinnlos sein.
Und temp1 bis temp3 hast du ja schon durch die hartkodierten Felder ersetzt, oder 8)
Um das auslesen von excel mit deiner OLE-Lösung in der 2. Zeile zu beginnen, mach einfach so:
--- Code: --- row = 1 ' 1 nicht 0 !!! These integers intialize to zero anyway
--- Ende Code ---
Rest dürfte nicht so schwer sein.
Schaus dir zur Not im debugger an.
... und lösch nicht-mehr-sinnvolle Zeilen, sonst ärgerst du oder dein Nachfolger sich in 8 Wochen, wenn da ein neues Feld in Excel eingefügt wird. ;D
bob:
Hi,
Vielen danke Axel! :)
Das "row" hatte mich verwirrt, da hatte ich angenommen da sind die einzelnen Zeilen gemeint........
Jetzt ist fast alles prima, allerdings suche ich noch nach einer Möglichkeit, dass die Angabe der zu übernehmenden Excel-Zeilen automatisch läuft.
Also:
- nimm Zeile 1, wenn nicht leer
- nimm Zeile 2, wenn nicht leer
etc.
Sobald "leer", dann übernehme nix mehr.......
Wie könnte ich denn das realisieren?
bye Bob
P.S. Hier der fertige Code:
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 value for excel file : c:\Import.xls
' 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 = 1 'Zeile ab der gestartet wird; 0 = 1.Zeile, 1 = 2.Zeile, etc.
written = 0
Print "Starting import from Excel file..."
Do While True
Finish:
With xlSheet
row = row + 1
' Set view = db.GetView
Set doc = db.CreateDocument 'Create a new doc
doc.Form = FormName
'...set value of doc...
Set item = doc.ReplaceItemValue("KSt_KSt", .Cells( row, 1 ).Value ) 'Hier Feldbezeichnung 1 ggf. ändern!
Set item = doc.ReplaceItemValue("KSt_Bezeichnung", .Cells( row, 2 ).Value ) 'Hier Feldbezeichnung 2 ggf. ändern!
Set item = doc.ReplaceItemValue( "KSt_Verantwortung", .Cells( row, 3 ).Value ) 'Hier Feldbezeichnung 3 ggf. ändern!
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
Navigation
[0] Themen-Index
[*] Vorherige Sete
Zur normalen Ansicht wechseln