excel with vb.net

i found 2 ways to read excel file in vb.net-

one with OleDb and the other one using com (Excel Library Com).

what is the different between them? what should i use in order to read excel file and also csv file?

thanks in advanced.

[254 byte] By [ppl1] at [2007-12-23]
# 1

OleDb method basically acts like a database method of retrieving data and so on. So you could retrieve data/query data like you do with SQL Server (SqlCommand)

the Com approach I believe allows you more flexibility in terms of what you can do with the spreadsheet (although I've never used it so I'm going from what i have read here on the forums)

Which approach to use is completely up to you depending on what you want to do.

ahmedilyas at 2007-8-30 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 2
One thing to keep in mind...If you use the Interop (com Excel Library) you and your application users must have Excel installed on thier machine. Using the oledb method you and your users only need access to the xl file
DMan1 at 2007-8-30 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 3

Oledb allows you to read the excel file as you would a database.

Using the COM interop (requires that you have Excel on the client machine) but you can basically automate any task you can do in excel and execute it from a VB application. So reading the contents is one example, but you can automate the creation formatting, exporting, entering of data / formula's into existing spreadsheets or newly created ones - basically the full functionality of excel is available to you from VB.Net

So a lot of functionality is open to you - which isnt available through just using OleDB.

But obviously it depends upon your specific requirements.

Reading a CSV file doesnt even require use of Excel or OleDB - as csv as straight text file TextfieldParser or streamreader are options for this.

spotty at 2007-8-30 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 4

ok

thanks for all the help

ppl1 at 2007-8-30 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 5
Hi!

I'm using an OLEDB connection to read an excel file... but it doesn't works when the file is openned by another user.

So, how modify the connection string in order to read the file --readonly ?

My code looks like this:

(...)

ConnectionString = "Provider=Microsoft.Jet.OleDb.4.0;Data Source=" & filename & ";Extended Properties=""Excel 8.0;IMEX=1;HDR=yes"""

sqlStr = "select * from [" & sheetname & "$A8:AD" & filas.ToString & "]"
(...)

Thanx....
I'd appreciate your suggesstions!

MariamCR at 2007-8-30 > top of Msdn Tech,Visual Basic,Visual Basic Language...