.Net 下读取Excel文件

来源:互联网 发布:ui 网络 存储 编辑:程序博客网 时间:2024/05/24 07:04

读取Excel文件内容:

string StrConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + FilePath + ";" + "Extended Properties=Excel 8.0;";
OleDbConnection MyConn = new OleDbConnection(StrConn);
// MyConn.Open();
string StrExcel = "";
OleDbDataAdapter MyCommand = null;
DataSet ds = null;
StrExcel = "select * from [sheet1$]";
MyCommand = new OleDbDataAdapter(StrExcel, StrConn);
ds = new DataSet();
MyCommand.Fill(ds, "table1");
//MyConn.Close();
return ds.Tables["table1"]; 

原创粉丝点击