It is possible to use OleDB and use Excel worksheets, such as data in a database ...
Just an example .....
string con = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\temp\test.xls;" + @"Extended Properties='Excel 8.0;HDR=Yes;'"; using(OleDbConnection connection = new OleDbConnection(con)) { connection.Open(); OleDbCommand command = new OleDbCommand("select * from [Sheet1$]", connection); using(OleDbDataReader dr = command.ExecuteReader()) { while(dr.Read()) { var row1Col0 = dr[0]; Console.WriteLine(row1Col0); } } }
This example uses the Microsoft.Jet.OleDb.4.0 provider to open and read an Excel file. However, if the file is of the xlsx type (from Excel 2007 and later), you need to download the Microsoft Access Database Engine components and install it on the target machine.
The provider is called Microsoft.ACE.OLEDB.12.0; . Please note that there are two versions of this component: one for 32-bit and one for 64-bit. Choose the appropriate version for your application bits and Office (if any). There are many quirks for this driver to work correctly for your application. See this question for example .
Of course, you do not need Office installed on the target machine.
Although this approach has some advantages, I think you should pay special attention to the link that the comment in your question on reading Excel files from C # reports. There are some problems regarding the correct interpretation of data types, and when the length of the data present in one excel cell is longer than 255 characters
Steve Apr 03 '13 at 17:00 2013-04-03 17:00
source share