1         /// <summary>
 2         ///
 3         /// 塗聚文
 4         /// 20120803
 5         /// Geovin Du
 6         ///找到EXCEL的工作表名称 要考慮打開的文件的進程問題
 7         /// </summary>
 8         /// <param name="filename"></param>
 9         /// <param name="comboBox2"></param>
10         /// <returns></returns>
11         public static System.Data.DataTable getSheetName(string filename, ComboBox comboBox2)
12         {
13             System.Data.DataTable dtSheets = new System.Data.DataTable();
14             try
15             {
16
17                 dtSheets.Columns.Add("id", typeof(int));
18                 dtSheets.Columns.Add("SheetName", typeof(string));
19                 object objOpt = Missing.Value;
20                 Excel.Application excelApp = new Excel.Application();
21                 excelApp.Workbooks.Open(filename, objOpt, objOpt, objOpt, objOpt, objOpt, true, objOpt, objOpt, true, objOpt, objOpt, objOpt, objOpt, objOpt);
22                 for (int i = 0; i < excelApp.Workbooks[1].Worksheets.Count; i++)
23                 {
24                     Excel.Worksheet ws = (Excel.Worksheet)excelApp.Workbooks[1].Worksheets[i + 1];
25                     string sSheetName = ws.Name;
26                     dtSheets.Rows.Add(i, ws.Name);
27                 }
28                 comboBox2.DataSource = dtSheets;
29                 comboBox2.DisplayMember = "SheetName";
30                 comboBox2.ValueMember = "id";
31                 comboBox2.AutoCompleteMode = AutoCompleteMode.Suggest;
32                 comboBox2.AutoCompleteSource = AutoCompleteSource.ListItems;
33                 KillExcelProceed();
34                 Kill(excelApp);
35             }
36             catch (IOException ex)
37             {
38                 ex.Message.ToString();
39             }
40             return dtSheets;
41         }
42         /// <summary>
43         ///
44         /// 塗聚文 締友計算機信息技術有限公司
45         /// 20120803
46         /// Geovin Du
47         /// </summary>
48         /// <param name="filename"></param>
49         /// <param name="comboBox2"></param>
50         /// <returns></returns>
51         public static System.Data.DataTable getGeovinDuSheetName(string filename, ComboBox comboBox2)
52         {
53             System.Data.DataTable dtSheets = new System.Data.DataTable();
54
55
56             try
57             {
58
59                 dtSheets.Columns.Add("id", typeof(int));
60                 dtSheets.Columns.Add("SheetName", typeof(string));
61                 string connectionString = String.Format(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties=""Excel 8.0;HDR=YES;IMEX=1;""", filename); //高版本用:Microsoft.ACE.OLEDB.12.0
62                 DbProviderFactory factory = DbProviderFactories.GetFactory("System.Data.OleDb");
63                 DbConnection connection = factory.CreateConnection();
64                 connection.ConnectionString = connectionString;
65                 connection.Open();
66                 DataTable tbl = connection.GetSchema("Tables");
67                 connection.Close();
68                 int i = 0;
69                 foreach (DataRow row in tbl.Rows)
70                 {
71                     string sheetName = (string)row["TABLE_NAME"];
72                     if (sheetName.EndsWith("$"))
73                     {
74                         sheetName = sheetName.Substring(0, sheetName.Length - 1);
75                     }
76                     //繁體系統需要此操作,簡體的不需要也可以
77                     sheetName = sheetName.Replace("$", "");
78                     sheetName = sheetName.Replace("'", "");
79                     dtSheets.Rows.Add(i,sheetName.Replace("$", ""));
80                     i++;
81                 }
82                 comboBox2.DataSource = dtSheets;
83                 comboBox2.DisplayMember = "SheetName";
84                 comboBox2.ValueMember = "id";
85                 comboBox2.AutoCompleteMode = AutoCompleteMode.Suggest;
86                 comboBox2.AutoCompleteSource = AutoCompleteSource.ListItems;
87
88                 return dtSheets;
89             }
90             catch (IOException ex)
91             {
92                 ex.Message.ToString();
93                 return null;
94             }
95
96         }

csharp read excel file get sheetName list相关推荐

  1. easypoi必填项_GitHub - wangjingting/poi-utils: help you more easy read or write excel file

    author:邹凯明 poi-utils help you more easy reading or writing[TODO] excel file 本工具包入口类是ExcelFileUtil,对于 ...

  2. MICROSOFT EXCEL FILE FORMAT(BIFF2.1)

    转自:http://www.xgdown.com/article/243/61822_1.htm 作用:http://unruledboy.cnblogs.com/archive/2004/07/07 ...

  3. 【Python】Pandas Excel file format cannot be determined, you must specify an engine manually.报错【已解决】

    Pandas读取Excel报错 Excel file format cannot be determined, you must specify an engine manually. pd.read ...

  4. The 13th tip of DB Query Analyzer, powerful processing EXCEL file

    The 13thtip of DB Query Analyzer, powerful processing EXCEL file MA Genfeng (Guangdong UnitollServic ...

  5. Excel file format cannot be determined, you must specify an engine manually

    大家在利用pandas读取excel文件的时候,一定会碰到类似的问题:这里主要写一下我踩过的坑: #官网pandas对engine的解释 enginestr, default None If io i ...

  6. RobotFramework环境配置十七:数据驱动(Read Excel File)

    数据驱动 RIDE提供的库: Create List Get File Import Variables Template ExcelLibrary 自定义库:DataCenter.py Read D ...

  7. c# Create Excel file and save as PDF

    方法一: 引用库: FreeSpire.XLS(VS NuGet 里面能直接找到) //void ConvertToPDF(string Path,string filename)//{// Spir ...

  8. SharePoint中excel file无法打开,弹出The file is corrupted and cannot be opened的解决方案

     最近收到一个用户反馈,在SharePoint中打开excel文件时弹出下面错误信息"The File is corrupt and cannot beopened." 在tr ...

  9. Apache POI 读写 Excel file (.xls or .xlsx)

    Apache POI 是 Apache 软件基金会的开放源码函式库,POI 提供 API 给 Java 程序对 Microsoft Office 格式档案读和写的功能. 这里演示了 POI 对新版 E ...

最新文章

  1. 《程序员代码面试指南》第五章 字符串问题 拼接所有字符串产生字典顺序最小的大写字符串...
  2. Java类与对象——几个课堂例子的总结及作业
  3. 设计模式系列之过滤器模式(Chriteria Pattern)
  4. 【环球产品探寻 4】Wolftech News拥有一流用户体验的媒体工作流系统 - 挪威
  5. 苹果airplay是什么 苹果手机投屏到电脑
  6. 红旗linux桌面版_瑞星ESM杀毒软件For Linux获红旗兼容性认证
  7. 接入百度智能云文字识别OCR记录
  8. 2021-2027全球与中国USB C型集线器市场现状及未来发展趋势
  9. 2022中国汽车品牌魅力指数排名:广汽传祺、吉利、东风风行、荣威位居自主品牌前列 | 美通社头条...
  10. 如何从零开始写一个操作系统?
  11. 女程序员的工位,藏着她们鲜衣怒码的人生 | 3·8特辑
  12. 主板装机测试软件,主板检测工具:PSPident v0.74.1版发布
  13. 关于C语言输出ASCII码128~255和有符号char型溢出的问题。此处大坑弄明白了后记录下来分享……
  14. 文件服务器报502,SFTP文件管理-服务端发生错误502、504
  15. python 优雅的写法_优雅的python写法
  16. interrupt request level - IRQL (驱动开发中关于IRQL级别说明)
  17. 如何无损压缩证件照?有没有免费的方法
  18. 极兔快递单号查询 快递鸟API接口对接指南-极兔速递
  19. 顺序表之两个有序顺序表合并
  20. linux运维监控内容,Linux运维工程师要掌握的常用监控指标总结

热门文章

  1. 模拟微信支付服务器测试,专栏 - 腾讯WeTest-All Test in WeTest
  2. alibaba 实体转json_com.alibaba.fastjson 转换List Map等对象
  3. java语言怎么建立窗口awt,java.awt.Frame类:创建窗口
  4. 摆胯教学分解_聚十年求索,筑理想课堂——厦门市梧侣学校十周年庆区级教学小学数学(数与形)...
  5. caany边缘检测matlab,自适应canny算法研究及其在图像边缘检测中的应用.pdf
  6. 69讲入门python_Python入门,一定要吃透这69个内置函数
  7. 【JAVA基础篇】运算符
  8. 编译linux内核适用的编译器,编译Linux内核时,CC,LD和CC [M]输出的代码是什么?...
  9. 如何制作一条网线?(双绞线在水晶头中的排列顺序)
  10. 插入排序之表插入排序