Importing Excel Data using Lotus Notes

does anybody have a script/ formula in uploading excel data using lotus notes?
ememAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
madheeswarConnect With a Mentor Commented:
Sorry, it should be:
set curdoc=ws.currentdocument.document

so ur a novice in Lotus Script?
0
 
madheeswarCommented:
Sub Initialize
 Dim FileNum As Integer
 Dim xlFilename As String

 Filenum% = Freefile()
 xlFileName$ = Inputbox("What file name and path? example:H:
\June282001.xls")

 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 row As Integer
 Dim written As Integer

 '// 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..."
 Set Excel = CreateObject( "Excel.Application.8" )
 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 = 0 '// These integers intialize to zero anyway
 written = 0

 Print "Starting import from Excel file..."

 Do While True
Finish:
 With xlSheet
 row = row + 1
 Set view = db.GetView("Main View")
 Set doc = db.CreateDocument '// Create a new doc
 doc.Form = "ImportForm1"

 If .Cells (row, 1).Value = "" And .Cells(row,2).Value = ""
And .Cells (row, 3).Value = "" And .Cells(row,4).Value = "" And .Cells
(row, 5).Value = "" And .Cells(row,6).Value = "" And .Cells (row, 7).Value
= "" And .Cells(row,8).Value = "" And .Cells (row, 9).Value = "" And
.Cells(row,10).Value = ""Then
 Goto Finish
 End If

 If .Cells (row, 1).Value = "PO #" And .Cells(row,2).Value
= "Order #" And .Cells (row, 3).Value = "Order da" And .Cells(row,4).Value
= "Part #" And .Cells (row, 5).Value = "Or" And .Cells(row,6).Value
= "Line " And .Cells (row, 7).Value = "Qty" And .Cells(row,8).Value
= "Unit pri" And .Cells (row, 9).Value = "Ship to Company" And
.Cells(row,10).Value = "Ship method"Then
 Goto Finish
 End If


 doc.SWEPO = .Cells( row, 1 ).Value
 doc.SWEORDER = .Cells(row, 2 ).Value
 doc.SWEORDERDATE = .Cells(row, 3).Value
 doc.ITEMNUMBER = .Cells( row, 4 ).Value
 doc.ORDERSTATUS = .Cells(row, 5).Value
 doc.QUANTITYORDERED = .Cells( row, 6).Value
 doc.AMOUNTBILLED = .Cells(row, 7).Value
 doc.SHIPMETHOD = .Cells( row, 8).Value
 doc.SHIPDATE = .Cells(row, 9).Value
 doc.TRACKINGNUMBER = .Cells(row, 10).Value


 Call doc.Save( True, True ) '// Save the new doc

 written = written + 1
 Print written
 If written = 5 Then
 Print written
 Goto Finish
 Else
 Print written
 Messagebox "Finished"
 Goto Done
 End If
 End With
 Loop
 Return
Done:
End Sub


This imports data from Excel into Lotus Notes, skipping blank lines and column headers. This will only import 100 records at a time and can be changed by changing the written value.
0
 
Bozzie4Commented:
You can also search this forum, you know, this has been asked at least a 1000 times before ....

cheers,

Tom
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
ememAuthor Commented:
thanks guys ....i'll try this out ......madheeswar the agent still does not work it has to be done manually.  I was thinking if possible that every day when the database is opened it will prompt the user to run the agent .......thanks again
0
 
ememAuthor Commented:
one more thing where will I post this code do i have to create a script library or just an action button to upload?
0
 
madheeswarCommented:
very strange...

Lets discuss this agent topic in that topic.
0
 
madheeswarCommented:
I placed this code in an agent and called the agent from an Action Button
@Command([ToolsRunMacro];"agentname")

0
 
ememAuthor Commented:
I see i'll work on that and get back to you ASAP
0
 
ememAuthor Commented:
The message finished was displayed but where can I view the data?
0
 
madheeswarCommented:
It will display in the views . And ur using some form to create documents using this code. So, give the selection formula in the view using this form and u can view all the docuemnts created by this agent.,
0
 
ememAuthor Commented:
I noticed that I  have to type the entire path of where the file is located can I just browse for the file in the directory?
0
 
madheeswarCommented:
You are free to change my code.

or place this code in a button and create a field on the form and browse for the file and the code should take the path and execute.
0
 
ememAuthor Commented:
oops! can you spare me a sample code? i'll increase your points ...my filename will be in this path and I will just browse for the file I want to upload ......please =)

C:\pdc\
0
 
madheeswarCommented:
Create a field called path_x
and create a button and place this code*this code will take the path of file.
Sub Click(Source As Button)
      Dim workspace As New NotesUIWorkspace
      Dim files As Variant
      On Error Goto ErrorHandler
      files = workspace.OpenFileDialog(True, "File List", _
      "", "c:")
      Dim messagelist As String
      Forall filelist In files
      'messagelist = messagelist & filelist & Chr(10)
            messagelist = messagelist & filelist
      End Forall
      Dim uidoc As notesuidocument
      Set uidoc=workspace.currentdocument
      
      Call uidoc.fieldsettext("path_x",messagelist)
ErrorHandler:
      Resume Next
      'Messagebox messagelist
End Sub
0
 
madheeswarCommented:
and use this field as the path instead of having alert in my previous code.

0
 
ememAuthor Commented:
ok ok im so excited get back soon!!!
0
 
ememAuthor Commented:
I created a form created everything that you told me and inserted an action button in the form where the first code you gave me to upload but nothing is uploaded ....=( hmm where do you think I will put the uploading script in the form? thanks a million
0
 
madheeswarCommented:
in hotspot button.
0
 
ememAuthor Commented:
I created this setup

created a form with the field path_x with 2 hotspot buttons browse(with the code you gave me to browse) upload (with this command @command([Toolsrunmacro];"Import") to call the agent we created.  But when I click on upload an error appeared when I debug it shows that the xlFileNames$ is blank it cannot hold the value of the filed path_x...did I miss something out? Do I have to declare path_x somewhere for it to be a global variable?

I change your original code

FROM =>xlFileName$ = Inputbox("What file name and path? example:H:\June282001.xls")

TO => xlFileName$ = path_x
0
 
madheeswarCommented:
it should be:
dim ws as new notesuiworkspace
dim curdoc as notesdocument
dim curdoc=ws.currentdocument.document
xlFileName$ = curdoc.path_x (0)
0
 
ememAuthor Commented:
copied the code in the agent you created but got an error in the line

dim curdoc=ws.currentdocument.document
0
 
ememAuthor Commented:
you can say that again my first time to handle scripting and to handle this kind of system PPHEW! thank GOD you are there =)
0
 
ememAuthor Commented:
it worked!!!!!! GREAT SCOTT you are a GURU in lotus ......i'll fix the display and get back to you on the agent THANKS!!!!!!! i'll accept this solution thanks thanks thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.