public DataTable ExcelToDT()
{
DataTable dt = new DataTable();
string filePath = Application.StartupPath + @"\Skills_TreeView\Skills.xls";
string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + filePath + ";" + "Extended Properties=Excel 8.0;";
using ( OleDbConnection conn = new OleDbConnection(strConn))
{
conn.Open();
string strExcel = "select * from [sheet1$]";
OleDbDataAdapter myCommand = new OleDbDataAdapter(strExcel, strConn);
myCommand.Fill(dt);
}
return dt;
}
C#Winformd读取excel文件数据转化为DataTable
最新推荐文章于 2024-09-10 14:09:51 发布