The following is the Agent which is used to import the datas from excel using xpages.
1. Create an excel sheet relevant to the Form
2. Write the following code in the Agent
Sub Initialize
Print “agent is runing”
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 One As String
Dim xlFilename As String
Dim filepath As Variant
Dim row As Integer
Dim written As Integer
‘// Connect to Excel and open the file. Start pulling over the records.
Dim Excel As Variant
Dim xlWorkbook As Variant
Dim xlSheet As Variant
‘filepath=ws.Openfiledialog(False, ” Open excel file” ,”*.xls”, “E:\New Folder”, “employeeDetails.xls”)
filepath=”E:\New Folder\Emp_Details.xls”
xlFilename=filepath
Print “File path is :” +filepath
Print “Connecting to Excel…”
Set Excel = createobject( “Excel.Application” )
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
Records:
row = 1 ‘// Integers intialize to zero
written = 0
‘MsgBox “Starting import from Excel file…”
Do While True
Finish:
With xlSheet
row = row + 1
Set doc = db.createdocument ‘// Create a new doc
doc.Form = “frm_employeeDetails”
If .Cells( row, 1 ).Value=”" Then
Exit Sub
End If
doc.name = .Cells( row, 1 ).Value
doc.department = .Cells(row, 2 ).Value
doc.designation = .Cells(row, 3).value
doc.mobno = .Cells(row, 4).Value
Call doc.Save( True, True ) ‘// Save the new doc
‘GoTo Done
written = written + 1
Print Str(written)
If .Cells( row, 1 ).Value = “” Then
GoTo Done
End If
End With
Loop
Return
Done:
print “Import Complete – Total number of documents imported —> ” & written
End Sub
Sub Initialize
Print “agent is runing”
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 One As String
Dim xlFilename As String
Dim filepath As Variant
Dim row As Integer
Dim written As Integer
‘// Connect to Excel and open the file. Start pulling over the records.
Dim Excel As Variant
Dim xlWorkbook As Variant
Dim xlSheet As Variant
‘filepath=ws.Openfiledialog(False, ” Open excel file” ,”*.xls”, “E:\New Folder”, “employeeDetails.xls”)\\Gine the Folder name here
filepath=”E:\New Folder\Emp_Details.xls”
xlFilename=filepath
Print “File path is :” +filepath
Print “Connecting to Excel…”
Set Excel = createobject( “Excel.Application” )
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
Records:
row = 1 ‘// Integers intialize to zero
written = 0
Do While True
Finish:
With xlSheet
row = row + 1
Set doc = db.createdocument ‘// Create a new doc
doc.Form = “frm_employeeDetails”
If .Cells( row, 1 ).Value=”" Then
Exit Sub
End If
doc.name = .Cells( row, 1 ).Value
doc.department = .Cells(row, 2 ).Value
doc.designation = .Cells(row, 3).value
doc.mobno = .Cells(row, 4).Value
Call doc.Save( True, True ) ‘// Save the new doc
‘GoTo Done
written = written + 1
Print Str(written)
If .Cells( row, 1 ).Value = “” Then
GoTo Done
End If
End With
Loop
Return
Done:
print “Import Complete – Total number of documents imported —> ” & written
End Sub
1. Create one button in Xpage and add the following code in the PostSaveDocument in the DataSource in the page which is used to execute the agent
var agen=database.getAgent(”[agentNae]“);
var uid=document2.getDocument().getNoteID();
agen.run(uid);
No comments:
Post a Comment