读取Excel文档
//Get Data from Excel file
public static DataTable ReadDataFromExcel(string queryString, string excelFile)
{
//string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties='Excel 8.0;IMEX=1';Data Source=@DataSource;";
string strConn = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=@DataSource;Extended Properties=""Excel 12.0;HDR=YES;""";
strConn = strConn.Replace("@DataSource", excelFile);
System.Data.OleDb.OleDbConnection cn = new System.Data.OleDb.OleDbConnection(strConn);
cn.Open();
System.Data.DataSet dsexcel = new DataSet();
System.Data.OleDb.OleDbDataAdapter sqlda = new System.Data.OleDb.OleDbDataAdapter(queryString, strConn);
sqlda.Fill(dsexcel);
cn.Close();
return dsexcel.Tables[0];
}
}