Results 1 to 4 of 4

Thread: Reading Excel file Fast

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 1999
    Location
    Ont, Canada, Earth
    Posts
    458

    Reading Excel file Fast

    Hi,
    I'm new to using Excel through VB.

    1.I'm given an .xls file with some rows of numbers (don't know how many) and that .xls file will be overwritten periodically with a new one

    2.My VB app will reside on a server and be running across local network on several workstations and will read the curent .xls file every hour show the newly updated data from that file

    3.I don't know how many rows of data will there be for me to read (that will change as the excel file is overwritten).

    4.Because all those workstations will be accessing the same .xls file, the read/accessing should be done quickly.

    Any examples will be appreciated.
    Thanks

    Tomexx.

  2. #2
    Frenzied Member DeadEyes's Avatar
    Join Date
    Jul 2002
    Posts
    1,196

    Re: Reading Excel file Fast

    You code always try adodb
    VB Code:
    1. Set tmpConn = New Connection
    2.     tmpConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    3.                  "Data Source=" & strFileName & ";" & _
    4.                  "Extended Properties=""Excel 8.0;"""
    5. 'The provider assumes that the table of data begins with the upper-most,
    6. 'left-most, non-blank cell on the specified worksheet.
    7. 'SELECT * FROM [SheetName$] WHERE [Field Name] LIKE 'A%' ORDER BY [Field Name]
    8.     strSQL = "SELECT * FROM [Sheet1$]"
    9.     Set oRs = New Recordset
    10.     Call oRs.Open(strSQL, tmpConn)

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 1999
    Location
    Ont, Canada, Earth
    Posts
    458

    Re: Reading Excel file Fast

    Thanks, can you explain in more detail?
    Don't know much about adodb and I need to read values from excel sheet to show in my VB app.

    Oh yeah, I need to display the data in VB controls (textboxes etc)
    Thanks

    Tomexx.

  4. #4
    Frenzied Member DeadEyes's Avatar
    Join Date
    Jul 2002
    Posts
    1,196

    Re: Reading Excel file Fast

    With this method your treating the excel spreadsheet like a table in a database.
    You'll need to add a reference to ADO
    VB Code:
    1. Dim tmpConn as Connection
    2. Dim oRs as RecordSet
    3. Dim fld as Field
    4.  
    5. 'strFileName is the path to the Excel file.
    6. Set tmpConn = New Connection
    7.     tmpConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    8.                  "Data Source=" & strFileName & ";" & _
    9.                  "Extended Properties=""Excel 8.0;"""
    10. 'The provider assumes that the table of data begins with the upper-most,
    11. 'left-most, non-blank cell on the specified worksheet.
    12. 'SELECT * FROM [SheetName$] WHERE [Field Name] LIKE 'A%' ORDER BY [Field Name]
    13.     'this is the query which is just say get everything in Sheet1$.
    14.     'sheet one is the default name, yours might be set to something different.
    15.     strSQL = "SELECT * FROM [Sheet1$]"
    16.     Set oRs = New Recordset
    17.     Call oRs.Open(strSQL, tmpConn)
    18. 'oRs is the RecordSet this contains all the information that was in the spreadsheet
    19. 'to view this information
    20. While Not oRs.Eof
    21.   For Each fld in ors.Fields 'loop through each column
    22.    Text1.Text = Text1.Text & Field.Name & "=" & fld.Value & vbcrlf
    23.   Next
    24.   oRs.MoveNext
    25. Wend 'loop through each row

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width