Created
September 17, 2014 20:57
-
-
Save StachuDotNet/dd2fe487ff3a482a2ee2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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