Skip to content

Instantly share code, notes, and snippets.

@cwschroeder
Created July 1, 2013 09:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cwschroeder/5899664 to your computer and use it in GitHub Desktop.
Save cwschroeder/5899664 to your computer and use it in GitHub Desktop.
Read Excel file
private static void Read()
{
var fileName = string.Format(@"c:\temp\test.xlsx");
var connectionString = string.Format("Provider=Microsoft.Jet.OLEDB.4.0; data source={0}; Extended Properties=Excel 8.0;", fileName);
var adapter = new OleDbDataAdapter("SELECT * FROM [Tabelle1$]", connectionString);
var ds = new DataSet();
adapter.Fill(ds, "myDs");
var data = ds.Tables["myDs"].AsEnumerable();
foreach (var row in data)
{
Console.WriteLine(string.Format("1: {0}, 2: {1}.", row[0], row[1]));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment