惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

V
Visual Studio Blog
Recent Announcements
Recent Announcements
有赞技术团队
有赞技术团队
The GitHub Blog
The GitHub Blog
N
Netflix TechBlog - Medium
腾讯CDC
A
About on SuperTechFans
博客园 - 叶小钗
大猫的无限游戏
大猫的无限游戏
小众软件
小众软件
D
DataBreaches.Net
D
Docker
宝玉的分享
宝玉的分享
量子位
Microsoft Azure Blog
Microsoft Azure Blog
Martin Fowler
Martin Fowler
博客园 - 三生石上(FineUI控件)
Jina AI
Jina AI
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
V
V2EX
Last Week in AI
Last Week in AI
H
Help Net Security
Hugging Face - Blog
Hugging Face - Blog
M
MIT News - Artificial intelligence

博客园 - 卓如

混合使用Jquery Deferred和Angularjs的$timeout(转) AngularJs应用页面切换优化方案(转) 在IE7下使用angularjs(转) AngularJS 中的 Promise 和 设计模式(转) Installing Oracle and ArcSDE on separate servers 修改oracle内存占用 在设置窗体身份验证时设置个别页面不需要进行验证[转] 解决ASP.NET在IE10中Session丢失问题【转】 心理课堂:对付拖延症(转) Ado方式导入excel混用数据类型引起数据缺失问题解决方法 深入分析 Java 中的中文编码问题(转) 轻松实现坐标转换(转) WIN2003系统远程桌面多连接数设置终极大法 GIS理论(墨卡托投影、地理坐标系、地面分辨率、地图比例尺、Bing Maps Tile System)【转载】 两点坐标间距离的算法以及验证【转】 [转]判断一个点是否落在多边形内 wpf \silverlight 保存控件为图片 - 卓如 WPF 自定义快捷键命令(Command)(转) SelectNodes 表达式 - 卓如 - 博客园
获得excel的sheet名字
卓如 · 2009-07-30 · via 博客园 - 卓如

///
/// This mehtod retrieves the excel sheet names from
/// an excel workbook.
///
/// The excel file.
/// String[]
private 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();
    }
  }
}