Hallo zusammen,
erst einmal vielen Dank für das tolle Forum. Es hat mir schon mehrfach sehr geholfen wenn der Knoten im Kopf nicht weggehen wollte.
Jetzt Versuche ich mich erstmals an einer Agenten Programmierung mit LS, der mir aus einer CSV Datei Adressen Importieren soll.
In der Sandbox bin ich fündig geworden und habe folgendes Script angepasst:
Option Public
Sub Initialize
Dim session As New notessession
Dim db As notesdatabase
Dim doc As notesdocument
Dim fileNum As Integer, cells As Integer, k As Integer
Dim fileName As String
Dim InputStr As String, delimiter As String
Dim FieldArray As Variant
fileNum% = Freefile()
fileName$ = "C:\Users\...\Desktop\Adressen.csv" ' Location of your file
delimiter = ";" ' Delimiter of your file
cells = 43 ' How many cells + 1
k = 0
Open fileName$ For Input As fileNum%
Do While Not Eof(fileNum%)
Line Input #1, InputStr$
FieldArray = parseall(InputStr$, delimiter, cells)
response% = CreateDocument(FieldArray)
k = k + 1
Print "Document Created: " + Cstr(k)
Loop
Close fileNum%
End Sub
Function CreateDocument(FieldArray As Variant) As Integer
Dim session As New notessession
Dim db As notesdatabase
Set db = session.currentdatabase
Dim doc As New notesdocument(db)
If FieldArray(30)<> "" and FieldArray(31) <> "" Then
doc.Type = "Company"
else
doc.Type = "Person"
End if
doc.Title = FieldArray(29)
doc.FirstName = FieldArray(30)
'doc.MiddleIntial = FieldArray(3)
doc.LastName = FieldArray(31)
doc.Suffix = FieldArray(1)
doc.CompanyName = FieldArray(4) + " " + FieldArray(5)
doc.Depatment = FieldArray(33)
'doc.SametimeLogin = FieldArray(8)
doc.JobTitel = FieldArray(32)
doc.OfficeStreetAddress = FieldArray(12)
doc.OfficeCity = FieldArray(15)
'doc.OfficeState = FieldArray(12)
doc.OfficeZip = FieldArray(14)
doc.OfficeCountry = FieldArray(13)
'doc.StreetAddress = FieldArray(15)
'doc.City = FieldArray(16)
'doc.State = FieldArray(17)
'doc.Zip = FieldArray(18)
'doc.Country = FieldArray(19)
doc.OtherStreetAddress = FieldArray(7)
doc.OtherCity = FieldArray(10)
'doc.OtherState = FieldArray(22)
doc.OtherZip = FieldArray(9)
doc.OtherCountry = FieldArray(8)
'doc.PhoneNumber_8 = FieldArray(25)
doc.OfficeFaxPhoneNumber = FieldArray(18)
doc.OfficePhoneNumber = FieldArray(17)
doc.PhoneNumber_9 = FieldArray(36)
doc.HomeFaxPhoneNumber = FieldArray(37)
doc.PhoneNumber = FieldArray(39)
'doc.PhoneNumber_10 = FieldArray(31)
doc.CellPhoneNumber = FieldArray(19)
doc.PersPager = FieldArray(38)
doc.PhoneNumber_6 = FieldArray(40)
'doc.Anniversary = FieldArray(35)
'doc.Manager = FieldArray(36)
'doc.Assistant = FieldArray(37)
doc.Birthday = FieldArray(42)
doc.Categories = FieldArray(24)
'doc.Children = FieldArray(40)
'doc. = FieldArray(41)
doc.email_1 = FieldArray(20)
'doc.miscPhone1 = FieldArray(43)
'doc.miscPhone2 = FieldArray(44)
doc.miscPhone3 = FieldArray(41)
'doc.email_2 = FieldArray(46)
'doc.Location = FieldArray(47)
'doc.Comment = FieldArray(48)
'doc.Spouse = FieldArray(49)
doc.WebSite = FieldArray(21)
'doc.Blogsite = FieldArray(51)
Call doc.save(1,0)
End Function
Function parseall(Initialstr As String, delimiter As String, cells As Integer) As Variant
CRcr$ = Chr(13)
IniVar$ = initialstr
numchars = Len(IniVar$)
Redim cols(cells)
Redim coldata(cells)
cols (0) = 0
For numcol = 1 To cells
prevcol = cols(numcol -1 )
cols (numcol) = Instr (cols(numcol - 1) + 1, IniVar$, Delimiter$)
StartCol = Cols(numcol - 1) + 1
If Cols (numcol) = 0 Then
endcol = numchar + 1
Else
endcol = cols(numcol)
End If
FieldLenght = EndCol - StartCol
If FieldLenght <= 0 Then
FieldLenght = 50
End If
ColData(numcol) = Trim$(Mid$(IniVar$, StartCol, FieldLenght))
CRPos% = Instr (1, ColData(numcol), CRcr$)
If (CRPos% >= 1) And (numcol <=2) Then
TempStr$ = ColData(numcol)
ColData(numcol) = Trim$(Mid$(IniVar$, StartCol, CRPos%-1))
End If
If cols (numcol) = 0 Then Exit For
Next
parseall = coldata()
End Function
Mein Problem ist, dass er die csv komisch einliest...
Hab mal ein Bild angehängt.
Irgendwie scheint es so, dass er die Trenner (in meinem Fall Semikolon) nicht richtig umsetzt...
Hat einer eine Idee?
Vielen Danke für eure Mühe
Michael