Domino 9 und frühere Versionen > ND7: Entwicklung

Re: Importieren von Ecxel Datensätzen in eine Maske

(1/3) > >>

Klafu:

--- Zitat ---Sub Click(Source As Button)
'The action button is located on a view named Import1
     Dim ws As New NotesUIWorkspace
     Dim session As New NotesSession
     Dim db As NotesDatabase
     Set db = session.CurrentDatabase
     Dim view As NotesView
     Dim doc As NotesDocument
     Dim temp1 As String
     Dim temp2 As String
     Dim temp3 As String
     Dim temp4 As String
     Dim temp5 As String
     Dim temp6 As String
     Dim xlApp As Variant
     Dim xlSheet As Variant
     Dim cursor As Integer
     Dim recordcheck As String
     
     On Error Goto ERRORLABEL
     Dim FileName As String
     Dim DefaultFileName As String
     DefaultFileName="c:tempsheet.xls"
     
     NamePrompt$="Enter the complete Path and File Name of the Excel file to be imported:" &Chr(13)
     FileName=Inputbox(NamePrompt$,"Import File Name Specification",DefaultFileName,100,100)
     If FileName="" Then Goto SubEnd
     'Create an Excel object for the spreadsheet
     'It may be necessary to have the proper MS Office DLLs installed on the PC running this application
     'That is, the person must be able to open the XLS file with Excel
     Set xlApp = CreateObject("Excel.Application")
     xlApp.Application.Workbooks.Open Filename
'File not found will return ERR=213 and the routine will be ended
     With xlApp.workbooks.Add
     'Not sure what this line is for, unless it's to be sure that at least one workbook is present in the XLS file
     End With
'Stop
     Set xlSheet = xlApp.Workbooks(1).Worksheets(1)
     recordcheck="x"
     r=1 ' Row counter - first row contains fieldnames from the database;
'these fieldnames are not needed as long as the spreadsheet follows a specified format
     While recordcheck <>"0" And recordcheck <> "" And r<100
           'Recordcheck = "0" when there is no value in the first cell of the row,  if integer, or "", if string
           'Important - Set r to a value that will stop the import routine without missing any data, if the other criteria do not
'For this example, six columns are imported
           cursor=0
           r=r+1
           temp1=xlSheet.Cells(r,1).value
           recordcheck=Cstr(temp1)
           If recordcheck="0" Then Goto Finished ' Avoid generating empty record
           temp2=xlSheet.Cells(r,2).value
           temp3=xlSheet.Cells(r,3).value
           temp4=xlSheet.Cells(r,4).value
           temp5=xlSheet.Cells(r,5).value
           temp6=xlSheet.Cells(r,6).value
           'The above lines lines could be combined with those below, but keep separate for ease in debugging until ready to finalize the code
           Set doc = New NotesDocument(db)
           doc.Form = "frmName"
           doc.Field1 = temp1
           doc.Field2 = temp2
           doc.Field3= temp3
           doc.Field4 = temp4
           doc.field5 = temp5
           doc.field6 = temp6
           Call Doc.Save(True, False)
Finished:
     Wend
     Goto SubClose
     
ERRORLABEL:
     'Msgbox "An error was encountered."
     'Print "Error: " Error(), "   Err:" Err(), " Erl:" Erl()
     If Err=213 Then
           Messagebox Filename & " was not found. Verify Path and Filename, then try the Import again."
           Resume SubEnd
     Else
           Messagebox "Error" & Str(Err) & ": " & Error$
     End If
     Resume Next
SubClose:
     xlApp.activeworkbook.close
     xlApp.Quit
     Set xlapp = Nothing
     Set view=db.getview("import1")
     Call ws.viewrefresh
SubEnd:
End Sub

--- Ende Zitat ---


Kann ich damit auch in Notes 7.0.1 Datenbanken Masken mit Excel Felder füllen ?
Ich tu mir, was Script angeht, noch relativ schwer

gruß
Christoph

Axel:
Ich würde mal sagen ja. Ich wüsste nicht was dagegen sprechen sollte.

Aber eigentlich gehört das ins 7er Forum.



Axel

Klafu:
Ok, ist das dann für einen Agenten ?

Sorry, hab die Suchfunktion benützt und wollte keinen neuen Thread aufmachen  :)

Gruß
Christoph

koehlerbv:
Ich halte das für kreuzgefährlich - auf Code zurückgreifen, von dem so gar keine Ahnung hat!

Vorab: Zwischen LS in R4 und R7 gibt es - gerade, was solche Importaktionen angeht - keine Unterschiede. Wenn, dann waren / wären dies Bugs. Diffiziler sind Änderungen in MS Office-Produkten, unter Umständen funktioniert etwas in Excel 2000, aber nicht in Excel 2003 oder Excel 97.

Weiterhin: Der Code ist SO nicht für einen Agent bestimmt, könnte dort aber laufen - dann könntest Du das aber gleich in einem Button lassen. Im Backend läuft der Agent SO allerdings nicht.

Frage: Was hast Du überhaupt vor? Wieviel Aufwand bist Du bereit, dabei vor allem in LS- und VBA-Lernen zu investieren?

Bernhard

Klafu:
Ich will Dokumente mit Hilfe von Daten aus einer Excel Tabelle erstellen (so um die 140)
Ich würde es zuerst auf einer Replik der Datenbank testen damit die Orginal DB bei fehler nicht beschädigt wird


LS lernen wäre für mich bestimmt kein Fehler
ich würde aber fast Java bevorzugen

Gruß
Christoph

Navigation

[0] Themen-Index

[#] Nächste Seite

Zur normalen Ansicht wechseln