Overblog Tous les blogs Top blogs Économie, Finance & Droit Tous les blogs Économie, Finance & Droit
Editer l'article Suivre ce blog Administration + Créer mon blog
MENU

Cycle de progression Faire (quelque chose qui marche) -> comprendre ce que l’on fait/comment cela marche -> pousser plus loin les notions

Publicité

Se connecter à un classeur Excel 2007 (*.xlsx) via ADO.NET

Se connecter à un classeur Excel 2007 (*.xlsx) via ADO.NET
La chaine de connexion a la forme :
-          Provider=Microsoft.ACE.OLEDB.12.0;
-          Data Source=chemin complet vers le fichier Excel
-          Extended Properties=""Excel 12.0;HDR=YES;"""
private void button2_Click(object sender, EventArgs e)
        {
            System.Data.DataTable oDataTable = new DataTable();
            System.Data.OleDb.OleDbDataAdapter oOleDbDataAdapter = new System.Data.OleDb.OleDbDataAdapter();
            oOleDbDataAdapter.SelectCommand = new System.Data.OleDb.OleDbCommand();
            oOleDbDataAdapter.SelectCommand.Connection = new System.Data.OleDb.OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;
Data Source=C:Documents and SettingsromagnyMes documentsDIVERS.xlsx;Extended Properties=""Excel 12.0;HDR=YES;""");
            oOleDbDataAdapter.SelectCommand.CommandType = CommandType.Text;
            oOleDbDataAdapter.SelectCommand.CommandText = "SELECT [ContactID],[ContactName],[ContactFirstName],[ContactEmail],[ContactCategoryID] FROM [Contact$]";
 
            oOleDbDataAdapter.Fill(oDataTable);
 
            dataGridView1.DataSource = oDataTable;
        }

http://www.connectionstrings.com/default.aspx?carrier=excel2007
Publicité
Retour à l'accueil
Partager cet article
Repost0
Pour être informé des derniers articles, inscrivez vous :
Commenter cet article