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
using System.Threading.Tasks; | |
using System.Data.OleDb; | |
using System.Data; | |
using System.IO; | |
//Code | |
OleDbConnection oledbConn; | |
string path = "C:\\MyExcel.xlsx"; | |
if (Path.GetExtension(path) == ".xls") | |
{ | |
oledbConn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path + ";Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=2\""); | |
} | |
else if (Path.GetExtension(path) == ".xlsx") | |
{ | |
oledbConn = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties='Excel 12.0;HDR=YES;IMEX=1;';"); | |
} | |
oledbConn.Open(); |