码迷,mamicode.com
首页 > 其他好文 > 详细

把Excel转化为DataTable

时间:2016-01-12 19:22:02      阅读:123      评论:0      收藏:0      [点我收藏+]

标签:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.OleDb;

namespace Framework.Common
{
public class CommonClass
{
public static DataSet ExecleDs(string filenameurl, string table)
{

DataSet ds = new DataSet();

string strConn = "Provider=Microsoft.Jet.Oledb.4.0;Data Source=" + filenameurl + ";Extended Properties=‘Excel 8.0;HDR=YES;IMEX=1;‘";
using (OleDbConnection conn = new OleDbConnection(strConn))
{
conn.Open();

string tableName = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null).Rows[0][2].ToString().Trim();

OleDbDataAdapter odda = new OleDbDataAdapter("select * from [" + tableName + "]", conn);

odda.Fill(ds, table);
}

return ds;

}
}
}

把Excel转化为DataTable

标签:

原文地址:http://www.cnblogs.com/xsj1989/p/5125315.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!