Skip to content

Instantly share code, notes, and snippets.

@jbubriski
Last active December 14, 2015 23:19
Show Gist options
  • Save jbubriski/5164856 to your computer and use it in GitHub Desktop.
Save jbubriski/5164856 to your computer and use it in GitHub Desktop.
Reading an excel using the Microsoft.ACE.OLEDB driver.
var fileName = "file.xlsx";
var connectionString = String.Format(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=""Excel 8.0;HDR=YES;IMEX=1;""", fileName);
var query = "select * from [{0}$]";
using (var dataAdapter = new OleDbDataAdapter(string.Format(query, "worksheet name"), connectionString))
{
var dataSet = new DataSet();
dataAdapter.Fill(dataSet);
var myTable = dataSet.Tables[0];
foreach (DataRow dataRow in myTable.Rows)
{
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment