Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.