如何将EXCEL的数据复制到DATATABLE中?
网友回复:给50分就给你代码,呵呵
网友回复: /// <summary>
/// 由EXCEL转换成DataTable
/// </summary>
/// <param name="strpath"> 文件路径及文件名 </param>
/// <returns> </returns>
private DataTable XlsToDataTable(String strpath)
{
string strConn;
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;"
"Data Source=" strpath ";"
"Extended Properties=Excel 8.0;";
OleDbConnection conn = new OleDbConnection(strConn);
OleDbDataAdapter myCommand = new OleDbDataAdapter("SELECT * FROM [Sheet1$]", strConn);
DataTable dt = new DataTable();
myCommand.Fill(dt);
return dt;
}
注重Sheet1$,这是工作表的名字.