Question : Importing data from Excel

Hello,
I am trying to import data from Excel into our document Management system Laserfiche version 8

The need is basically to create a sort of lookup depending upon one of the field values of template & then the workflow should autmatically populate rest of the feilds.

I had also posted this question but by mistake in wrong place.
One of the persons had written a code to pull the data from SQL database, I am putting down the code so that you can have a look & make more sense of it than I can & it might help you to determine what exactly has to be done:
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
Private sqlCmd As SqlCommand
        Private sqlConn As SqlConnection
        Private sqlDr As SqlDataReader
        Private scn As String = "Initial Catalog=WFInvoices;Data Source=IKE;Integrated Security=SSPI;"
       
        Protected Overrides Sub Execute()
            Try
 
                Dim docid as Integer
                docid = Me.Entry.ID
 
                Dim InvoiceNumber as String  = ""
                Dim VendorName as String  = ""
                Dim Phone as String  = ""
                Dim Address as String  = ""
                Dim City as String  = ""
                Dim State as String  = ""
                Dim Zip as String  = ""
                Dim Description as String  = ""
 
                Dim lfDoc As LFDocument = me.Database.GetEntryByID(docid)
                Dim DocMetaData As LFFieldData = lfDoc.FieldData
                InvoiceNumber = DocMetaData.FieldByIndex(1)
 
 
                Dim sqlStr As String = "SELECT * FROM Invoices WHERE InvNum='" & invoiceNumber & "'"
                Dim sqlConn As New SqlConnection(scn)
                Dim sqlCmd As New SqlCommand(sqlStr, sqlConn)
                sqlConn.Open()
                Dim sqlDR As SqlDataReader
                sqlDR = sqlCmd.ExecuteReader()
 
                'Always call Read before accessing data.
                While sqlDR.Read()
 
                    VendorName = sqlDR.GetString(1)
                    Phone = sqlDR.GetString(2)
                    Address = sqlDR.GetString(3)
                    City = sqlDR.GetString(4)
                    State = sqlDR.GetString(5)
                    Zip = sqlDR.GetString(6)
                    Description = sqlDR.GetString(7)
 
                End While
 
                sqlDR.Close()
                sqlConn.Close()
                sqlConn.Dispose()
 
                'Update Document Template
                DocMetaData.FieldByIndex(2) = VendorName
                DocMetaData.FieldByIndex(3) = Phone
                DocMetaData.FieldByIndex(4) = Address
                DocMetaData.FieldByIndex(5) = City
                DocMetaData.FieldByIndex(6) = State
                DocMetaData.FieldByIndex(7) = Zip
                DocMetaData.FieldByIndex(8) = Description
                DocMetaData.Update()
                'lfDoc.Dispose()
 
 
                'Move the document to the vendor folder
                Dim parentFolder as LFFolder = me.Database.GetEntryByPath("\Vendors\" & VendorName)
                lfdoc.Move(parentfolder,true)
                lfDoc.Dispose
 
            Catch ex As Exception
 
 
            End Try
        End Sub

Answer : Importing data from Excel

OK, I see SQL Server elements (SqlDataReader, SqlConnection), so it now sounds like you are trying to use the System.Data.OleDb namespace instead of the System.Data.SqlClient namespace.

The cool part about the ADO.NET is the data provider pattern is that all .NET data providers much adhere to the same interface, so you can change to use the OleDb types by changing the prefix (SqlDataAdapter -> OleDbDataAdapter, SqlConnection -> OleConnection, and so on...).  All you would need to do is to get the appropriate Excel connection string for OLE DB:

Connection strings for Excel
http://www.connectionstrings.com/excel

OLEDB;Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\MyExcel.xls;Extended Properties="Excel 8.0;HDR=Yes;IMEX=1";
Random Solutions  
 
programming4us programming4us