Last active
August 29, 2015 14:18
-
-
Save Microsofttechies/3286110b0c0989a1f918 to your computer and use it in GitHub Desktop.
C# read excel OleDbConnection connection for .xls and .xlsx
This file contains hidden or 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(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment