c#获取excel中的所以sheet名称
2011-10-08 14:55
381 查看
Excel.Application myExcel = new Excel.Application(); object missing = System.Reflection.Missing.Value; myExcel.Application.Workbooks.Open(this.txtFile.Text, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing);//this.txtFile.Text为Excel文件的全路径 Excel.Workbook myBook = myExcel.Workbooks[1]; //获取第一个Sheet Excel.Worksheet sheet = (Excel.Worksheet)myBook.Sheets[1]; string sheetName = sheet.Name; //Sheet名 //获取全部Sheet名 public static StringCollection ExcelSheetName(string filepath) { StringCollection names = new StringCollection(); string strConn; strConn = "Provider=Microsoft.Ace.OLEDB.12.0;Data Source=" + filepath + ";Extended Properties='Excel 12.0;HDR=Yes;IMEX=2'"; OleDbConnection conn = new OleDbConnection(strConn); conn.Open(); DataTable sheetNames = conn.GetOleDbSchemaTable (System.Data.OleDb.OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" }); conn.Close(); foreach (DataRow dr in sheetNames.Rows) { names.Add(dr[2].ToString()); } return names; }
相关文章推荐
- C#获取Excel中所有的Sheet名称
- C#获取Excel中所有的Sheet名称
- C#获取Excel中所有的Sheet名称
- C#获取Excel中所有的Sheet名称
- C# 读取Excel中指定的Sheet名称或索引
- C# 读取Excel中指定的Sheet名称或索引
- C# 读取Excel中指定的Sheet名称或索引(转)
- excel获取所有的sheet文件名称
- C#可以获取Excel文件中Sheet的名字
- VB.Net获取Excel中Sheet的名称
- C# 读取Excel中指定的Sheet名称或索引
- C#读取excel工作表(sheet)中的内容-----采用名称的方法
- C# 读取Excel中指定的Sheet名称或索引
- 获取Excel的sheet名称和数量
- C#获取excel中sheel名称
- Excel导入时,如何获取第一个Sheet名称
- C# 读取Excel中指定的Sheet名称或索引
- C#获取Excel全部的sheet
- 在SQL Server中获取Excel文件中所有Sheet工作表的名称
- 获取Excel中的Sheet的名称