C#获取Excel中所有的Sheet名称
来源:互联网 发布:图片推荐算法 编辑:程序博客网 时间:2024/04/30 11:50
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;
}
备注:操作完后要关闭:
myBook.Close(Type.Missing,Type.Missing,Type.Missing);
myExcel.Quit();
- C#获取Excel中所有的Sheet名称
- C#获取Excel中所有的Sheet名称
- C#获取Excel中所有的Sheet名称
- c#获取excel中的所以sheet名称
- 得到Excel的所有Sheet名称
- 得到Excel的所有Sheet名称
- VB.Net获取Excel中Sheet的名称
- C#修改Excel的Sheet名称
- SQLServer获取Excel中所有Sheet
- SQLServer获取Excel中所有Sheet 收藏
- SQLServer获取Excel中所有Sheet
- excel获取所有的sheet文件名称
- C#获取Excel全部的sheet
- C# 读取Excel中指定的Sheet名称或索引
- C# 读取Excel中指定的Sheet名称或索引
- C# 读取Excel中指定的Sheet名称或索引
- C# 读取Excel中指定的Sheet名称或索引
- C# 读取Excel中指定的Sheet名称或索引
- 探索CLR原理系列(1):类型
- android TextView和EditText中显示图片
- 探索CLR原理系列(2):字段在内存中的布局
- SCA 之Tuscany 3 ——helloworld WebApp
- 云计算思想和概括
- C#获取Excel中所有的Sheet名称
- 终于弄用了,一个可拖拽(移动)、编辑、锁定和关闭的div层,自动排列
- USACO:Your Ride Is Here
- ubuntu 源
- Delphi 监控文件改变
- inline函数的一些总结
- Java中字节与无符号数之间的转换
- CMD下查看路由表
- android编译顺序