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.
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.
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.
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.
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!