- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
string filename = "pasker_ltd.xls";
string ConnectionString = String.Format("Provider=Microsoft.Jet.OLEDB.4.0; Data Source={0}; Extended Properties=Excel 8.0;", filename);
DataSet ds = new DataSet("EXCEL");
OleDbConnection cn = new OleDbConnection(ConnectionString);
cn.Open();
DataTable schemaTable =cn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables,new object[] { null, null, null, "TABLE" });
string sheet1 = (string)schemaTable.Rows[0].ItemArray[2];
string select = String.Format("SELECT * FROM [{0}]", sheet1);
OleDbDataAdapter ad = new OleDbDataAdapter(select, cn);
ad.Fill(ds);
DataTable tb = ds.Tables[0];
dataGridView1.DataSource = tb;
Комментарии (0) RSS
Добавить комментарий