最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
.net导入excel时获取第一个Sheet名称
时间:2022-06-25 06:05:24 编辑:袖梨 来源:一聚教程网
///
/// 根据excel的文件的路径提取其中表的数据
///
/// excel文件的路径
private void getdatafromexcelwithappointsheetname(string path)
{
//连接串
string strconn = "provider=microsoft.jet.oledb.4.0;" + "data source=" + path + ";" + "extended properties=excel 8.0;";
oledbconnection conn = new oledbconnection(strconn);conn.open();
//返回excel的架构,包括各个sheet表的名称,类型,创建时间和修改时间等
datatable dtsheetname = conn.getoledbschematable(oledbschemaguid.tables, new object[] { null, null, null, "table" });//包含excel中表名的字符串数组
string[] strtablenames = new string[dtsheetname.rows.count];
for (int k = 0; k < dtsheetname.rows.count; k++)
{
strtablenames[k] = dtsheetname.rows[k]["table_name"].tostring();
}oledbdataadapter mycommand = null;
datatable dt = new datatable();//从指定的表明查询数据,可先把所有表明列出来供用户选择
string strexcel = "select * from [" + strtablenames[0] + "]";
mycommand = new oledbdataadapter(strexcel, strconn);
dt = new datatable();
mycommand.fill(dt);datagridview1.datasource = dt; //绑定到界面
}
相关文章
- 免费漫画平台精选-免费看漫画的优质平台大全 02-16
- 千牛网页版登录-千牛工作台一键登录 02-16
- Sora官网入口地址在哪里-Sora官网入口地址全收录 02-16
- 汗汗漫画极速入口-汗汗漫画秒开无延迟 02-16
- 今日校园查成绩攻略-四六级成绩快速查询教程 02-16
- 哔哩哔哩网页版直达-bilibili网页版快捷登录 02-16