1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
this.connection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + openFileDialog.FileName + ";Extended Properties=Excel 8.0");
this.command = new OleDbCommand();
this.command.Connection = this.connection;
this.dateAdapter = new OleDbDataAdapter(this.command);
this.connection.Open();
DataTable table = connection.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" });
string SpreadSheetName = "["+table.Rows[0]["TABLE_NAME"].ToString()+"]";
this.command.CommandText = @"SELECT * FROM "+SpreadSheetName;
this.dateAdapter.Fill(dataSet1);
this.connection.Close();
this.dataGridView1.DataSource = this.dataSet1;
this.dataGridView1.DataMember = "Table"; |
Partager