Skip to content

Instantly share code, notes, and snippets.

@StachuDotNet
Created September 17, 2014 20:57
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 StachuDotNet/dd2fe487ff3a482a2ee2 to your computer and use it in GitHub Desktop.
Save StachuDotNet/dd2fe487ff3a482a2ee2 to your computer and use it in GitHub Desktop.
var da = new DataSet();
var adapter = new OleDbDataAdapter();
var path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
path += "asdf_5.xlsx";
var connectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path
+ @";Extended Properties=""Excel 12.0 Macro;HDR=YES;ImportMixedTypes=Text;TypeGuessRow=0""";
var conn = new OleDbConnection(connectionString);
const string strCmd = "select * from [Sheet1$A1:K3]";
var cmd = new OleDbCommand(strCmd, conn);
try
{
conn.Open();
da.Clear();
adapter.SelectCommand = cmd;
adapter.Fill(da);
Console.WriteLine(da.Tables[0]);
}
catch (Exception) { throw; }
finally
{
conn.Close();
}
Console.ReadLine();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment