/// <summary>
/// 读取Excel文件
/// </summary>
/// <returns></returns>
private DataTable ExcelRead()
{
string ConnStr = @"Provider=Microsoft.ACE.OLEDB.12.0;;data source=C:\Users\Administrator\Desktop\abc.xlsx;Extended Properties='Excel 12.0 Xml;HDR=False;IMEX=1'";
OleDbConnection OleConn = new OleDbConnection(ConnStr);
OleConn.Open();
string SQL = "select * from [Sheet1$]";
DataSet ds = new DataSet();
OleDbDataAdapter OleAd = new OleDbDataAdapter(SQL, OleConn);
OleAd.Fill(ds);
OleConn.Close();
return ds.Tables[0];
}
引用:
using System.Data.OleDb;