网站导航免费论文 原创论文 论文搜索 原创论文 网学软件 学术大家 资料中心 会员中心 问题解答 原创论文 论文素材 设计下载 最新论文 下载排行 论文上传 在线投稿 联系我们
返回网学首页
网学联系
最新论文 推荐专题 热门论文 素材专题
当前位置: 网学 > 编程文档 > C# > 正文
.net获得excel的sheet名字
来源:Http://myeducs.cn 联系QQ:点击这里给我发消息 作者: 用户投稿 来源: 网络 发布时间: 12/10/14
下载{$ArticleTitle}原创论文样式

 /// 

/// This mehtod retrieves the excel sheet names from /// an excel workbook./// /// The excel file./// Stringprivate String GetExcelSheetNames(string excelFile){  OleDbConnection objConn = null;  System.Data.DataTable dt = null;  try  {    // Connection String. Change the excel file to the file you    // will search.    String connString = "Provider=Microsoft.Jet.OLEDB.4.0;" +         "Data Source=" + excelFile + ";Extended Properties=Excel 8.0;";    // Create connection object by using the preceding connection string.    objConn = new OleDbConnection(connString);    // Open connection with the database.    objConn.Open();    // Get the data table containg the schema guid.    dt = objConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);     if(dt == null)    {      return null;    }    String excelSheets = new String[dt.Rows.Count];    int i = 0;    // Add the sheet name to the string array.    foreach(DataRow row in dt.Rows)    {      excelSheets[i] = row["TABLE_NAME"].ToString();      i++;    }    // Loop through all of the sheets if you want too    for(int j=0; j < excelSheets.Length; j++)    {      // Query each excel sheet.    }    return excelSheets;  }  catch(Exception ex)  {    return null;  }  finally  {    // Clean up.    if(objConn != null)    {      objConn.Close();      objConn.Dispose();    }    if(dt != null)    {      dt.Dispose();    }  }} 

网学推荐

免费论文

原创论文

浏览:
设为首页 | 加入收藏 | 论文首页 | 论文专题 | 设计下载 | 网学软件 | 论文模板 | 论文资源 | 程序设计 | 关于网学 | 站内搜索 | 网学留言 | 友情链接 | 资料中心
版权所有 QQ:3710167 邮箱:3710167@qq.com 网学网 [Myeducs.cn] 您电脑的分辨率是 像素
Copyright 2008-2015 myeducs.Cn www.myeducs.Cn All Rights Reserved
湘ICP备09003080号