Saturday, 13 September 2014

Import from Excel to Notes

Sample code used for  importing the data from excel file to notes using LotusScript.

code started from below :

Sub Initialize
Dim session As New notessession
Dim db As NotesDatabase
Dim form As NotesForm
Set db=session.CurrentDatabase
Set form = db.GetForm("FormName")

Dim xlapp As Variant
Dim xlworksheet As Variant
Dim xlsheet As Variant
Set xlapp = CreateObject("Excel.Application")
xlapp.Visible = False
Set xlworksheet = xlapp.Worksheet.Open("pathforfile")
Set xlsheet = xlworksheet.WorkSheet(1)

Dim rows, cols As Integer

xlsheet.Cells.SpecialCells(10).Active
rows= xlsheet.ActiveWindow.ActiveCell.row
Cols = xlsheet.ActiveWindow.ActiveCell.Column

Dim row As Integer
row =0

Do While True
row =row+1
If row = rows+1 Then
Goto Done
End If
If row =1 Then
For i=1 To cols
Redim Preserve fd(i) As String
fd(i) = xlsheet.cells(row,i).value
flag=0
Forall n In form.Fields
If Lcase(fd(i)) = Lcase(n) Then
flag=1
End If
End Forall
If flag=1 Then
Goto skip
End If
If Not flag=1 Then
Msgbox "Field name not appear in the form"
Goto Errhandler
End If

Skip :
Next
End If
If Not row=1 Then
Set doc = db.CreateDocument
doc.Form = formname
For i=1 To cols
Set item= doc.replaceitemvalue(fd(i), xlsheets.Cells(row,i).Value)
Next
End If
Done:
Call xlworksheet.Close
Call xlapp.Quit
Set xlapp=Nothing
Loop
Exit Sub
Errhandler:
Msgbox "Error on Line number : " &Erl() & "Error desc : " &Error()
End Sub

No comments:

Post a Comment