如何从Excel中读取文件到DataSet中
1个回答
展开全部
pprivate DataSet ExcelToDS(string Path)
{
string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + Path + ";" + "Extended Properties='Excel 8.0; HDR=YES; IMEX=1'";
using (OleDbConnection conn = new OleDbConnection(strConn))
{
DataSet ds = new DataSet();
try
{
conn.Open();
string strExcel = "select * from [sheet1$],[sheet2$],[sheet3$]";
OleDbDataAdapter command = new OleDbDataAdapter(strExcel, conn);
command.Fill(ds);
conn.Close();
}
catch
{
}
return ds;
}
}
以上。
{
string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + Path + ";" + "Extended Properties='Excel 8.0; HDR=YES; IMEX=1'";
using (OleDbConnection conn = new OleDbConnection(strConn))
{
DataSet ds = new DataSet();
try
{
conn.Open();
string strExcel = "select * from [sheet1$],[sheet2$],[sheet3$]";
OleDbDataAdapter command = new OleDbDataAdapter(strExcel, conn);
command.Fill(ds);
conn.Close();
}
catch
{
}
return ds;
}
}
以上。
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询