C#将EXCEL的数据复制到DATATABLE中?
1个回答
展开全部
///
<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$,这是工作表的名字.
<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$,这是工作表的名字.
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询