Excell .net 读取消信息

// 获取Excep文件的完整路径
string source = File1.Value;

string ConnStr = " Provider=Microsoft.Jet.OLEDB.4.0;DataSource= " + source + " ;ExtendedProperties=Excel8.0 " ;
string query = " SELECT*FROM[Sheet1$] " ;

OleDbCommandoleCommand
= new OleDbCommand(query, new OleDbConnection(ConnStr));
OleDbDataAdapteroleAdapter
= new OleDbDataAdapter(oleCommand);
DataSetmyDataSet
= new DataSet();

// 将Excel的[Sheet1]表内容填充到DataSet对象
oleAdapter.Fill(myDataSet, " [Sheet1$] " );

// 数据绑定
DataGrid1.DataSource = myDataSet;
DataGrid1.DataMember
= " [Sheet1$] " ;
DataGrid1.DataBind();

你可能感兴趣的:(.net,Microsoft,Excel)