zoukankan      html  css  js  c++  java
  • 如何获取excel对应的sheet个数和对应的名字

    public static int GetExcelTableCount(string filename) { DataTable dt = new DataTable(); OleDbConnection cnnxls = new OleDbConnection(); try { string mystring = "Provider = Microsoft.Jet.OLEDB.4.0 ;Extended Properties=Excel 8.0;Data Source =" + filename; cnnxls.ConnectionString = mystring; cnnxls.Open(); dt = cnnxls.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null); return dt.Rows.Count; } finally { cnnxls.Close(); } return 0; } public static string[] GetExcelTableNames(string filename) { DataTable dt = new DataTable(); OleDbConnection cnnxls = new OleDbConnection(); try { string mystring = "Provider = Microsoft.Jet.OLEDB.4.0 ;Extended Properties=Excel 8.0;Data Source =" + filename; cnnxls.ConnectionString = mystring; cnnxls.Open(); dt = cnnxls.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null); } finally { cnnxls.Close(); } List names = new List(); foreach (DataRow row in dt.Rows) { names.Add(row["TABLE_NAME"].ToString().Trim('/'', '$').Replace("''", "'").Replace("$$", "$")); } return names.ToArray(); }
  • 相关阅读:
    二分制--找最小值去重
    angular过滤 排序问题
    div+css背景渐变色代码
    angular中对象与字符串之间的转换
    AMD模块
    jquery.validate
    谈谈js中深度克隆和浅度克隆
    还在使用git吗?不妨来看看如何使用git管理版本
    闭包
    js复习
  • 原文地址:https://www.cnblogs.com/liaomin416100569/p/9331502.html
Copyright © 2011-2022 走看看