1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| string filePath = @"C:\Classeur1.xls";
string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filePath + ";Extended Properties=\"Excel 8.0\";";
OleDbConnection connection = new OleDbConnection(connectionString);
string cmdText = "SELECT * FROM [Feuil1$]";
OleDbCommand command = new OleDbCommand(cmdText, connection);
command.Connection.Open();
OleDbDataReader reader = command.ExecuteReader();
if (reader.HasRows)
{
while (reader.Read())
{
Console.WriteLine("{0}\t{1}", reader[0].ToString(), reader[1].ToString());
}
}
reader.Close();
command.Connection.Close(); |
Partager