/// <summary>
/// 使用oledb连接Excel
/// </summary>
/// <param name="_fileUrl"></param>
/// <param name="pageName"></param>
/// <returns></returns>
public DataSet ExcelConn(string _fileUrl, string pageName)
{
string filePath = _fileUrl;
OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
+ filePath + ";Extended Properties=\"Excel 8.0;IMEX=1\"");
conn.Open();
OleDbCommand cmd = new OleDbCommand("SELECT * FROM [" + pageName + "$]", conn);
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
conn.Close();
return ds;
}
实例:导入Excel.rar