I want to read excell file with this code:
var fileName = @"d:\1.xlsx";
var connectionString = string.Format(
"Provider=Microsoft.Jet.OLEDB.4.0; data source="+fileName+
"; Extended Properties=Excel 8.0;", fileName);
var adapter = new OleDbDataAdapter("SELECT * FROM [sheet1$]", connectionString);
var ds = new DataSet();
adapter.Fill(ds, "anyNameHere");
DataTable data = ds.Tables["anyNameHere"];
But when run the program I get this error:
An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in System.Data.dll
Additional information: External table is not in the expected format.
How can i solve that?