1 2 3 4 5 6 7 8 9 10 11 12 13 14
| string filePath = @"C:\Classeur1.xls";
string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filePath + ";Extended Properties=\"Excel 8.0\";";
using (OleDbConnection connection = new OleDbConnection(connectionString))
{
connection.Open();
// Le nom des colonnes se trouve en première ligne de la feuille.
// Ici les colonnes concernées s'intitulent COL 1 et COL 2 :
string cmdText = "INSERT INTO [Feuil1$] ([COL 1], [COL 2]) VALUES ('Valeur dans la cellule A1', 'Autre valeur dans la cellule A2')";
using (OleDbCommand command = new OleDbCommand(cmdText, connection))
{
command.ExecuteNonQuery();
}
} |
Partager