C#获取Excel里sheet名
2011-10-13 15:42
399 查看
public static DataTable GetExcelTable(string excelFilename)
{
string connectionString = string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Jet OLEDB:Engine Type=35;Extended Properties=Excel 8.0;Persist Security Info=False",excelFilename);
DataSet ds = new DataSet();
string tableName;
using (System.Data.OleDb.OleDbConnection connection = new System.Data.OleDb.OleDbConnection(connectionString))
{
connection.Open();
DataTable table = connection.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tables, null);
tableName = table.Rows[0]["Table_Name"].ToString();
string strExcel = "select * from " + "[" + tableName + "]";
OleDbDataAdapter adapter = new OleDbDataAdapter(strExcel, connectionString);
adapter.Fill(ds, tableName);
connection.Close();
}
return ds.Tables[tableName];
}
{
string connectionString = string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Jet OLEDB:Engine Type=35;Extended Properties=Excel 8.0;Persist Security Info=False",excelFilename);
DataSet ds = new DataSet();
string tableName;
using (System.Data.OleDb.OleDbConnection connection = new System.Data.OleDb.OleDbConnection(connectionString))
{
connection.Open();
DataTable table = connection.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tables, null);
tableName = table.Rows[0]["Table_Name"].ToString();
string strExcel = "select * from " + "[" + tableName + "]";
OleDbDataAdapter adapter = new OleDbDataAdapter(strExcel, connectionString);
adapter.Fill(ds, tableName);
connection.Close();
}
return ds.Tables[tableName];
}
相关文章推荐
- Asp.net(C#)中自动获取Excel的Sheet名
- C#获取Excel里sheet名,其表内容
- c# 获取Excel内容的分析
- C#获取Excel架构信息的方法
- C#获取Excel中所有的Sheet名称
- C# 操作Excel获取数据、时间、图片
- C#获取Excel和Access连接的写法
- C# 获取Excel中的合并单元格
- 在C#获取word文档的字数,并输出到excel
- C#操作office进行Excel图表创建,保存本地,word获取
- C#获取Excel全部的sheet
- 获取鼠标位置、C# 获取Excel鼠标位置、获取Excel 光标位置
- c#通过oledb获取excel文件表结构信息
- C# 获取Excel版本
- C# 获取Excel中数据
- c#通过oledb获取excel文件表结构信息
- C#基于OLEDB获取Excel文件表结构信息的方法
- C# 获取Excel列数据类型不一致的数据
- C#读取 excel中的表名sheet名不是默认的sheet1,shee2就取不到值了 c# 如何读取自定义的sheet值?c#读取excel最佳解决方案
- C# 获取文件信息并导出Excel,Xml报表