|
-
Feb 25th, 2005, 07:40 AM
#1
Thread Starter
Hyperactive Member
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.
-
Feb 25th, 2005, 08:18 AM
#2
Re: Reading Excel file Fast
You code always try adodb
VB Code:
Set tmpConn = New Connection
tmpConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & strFileName & ";" & _
"Extended Properties=""Excel 8.0;"""
'The provider assumes that the table of data begins with the upper-most,
'left-most, non-blank cell on the specified worksheet.
'SELECT * FROM [SheetName$] WHERE [Field Name] LIKE 'A%' ORDER BY [Field Name]
strSQL = "SELECT * FROM [Sheet1$]"
Set oRs = New Recordset
Call oRs.Open(strSQL, tmpConn)
-
Feb 25th, 2005, 08:50 AM
#3
Thread Starter
Hyperactive Member
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)
-
Feb 25th, 2005, 10:45 AM
#4
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:
Dim tmpConn as Connection
Dim oRs as RecordSet
Dim fld as Field
'strFileName is the path to the Excel file.
Set tmpConn = New Connection
tmpConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & strFileName & ";" & _
"Extended Properties=""Excel 8.0;"""
'The provider assumes that the table of data begins with the upper-most,
'left-most, non-blank cell on the specified worksheet.
'SELECT * FROM [SheetName$] WHERE [Field Name] LIKE 'A%' ORDER BY [Field Name]
'this is the query which is just say get everything in Sheet1$.
'sheet one is the default name, yours might be set to something different.
strSQL = "SELECT * FROM [Sheet1$]"
Set oRs = New Recordset
Call oRs.Open(strSQL, tmpConn)
'oRs is the RecordSet this contains all the information that was in the spreadsheet
'to view this information
While Not oRs.Eof
For Each fld in ors.Fields 'loop through each column
Text1.Text = Text1.Text & Field.Name & "=" & fld.Value & vbcrlf
Next
oRs.MoveNext
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|