如何获取excel对应的sheet个数和对应的名字
2011-06-02 10:56
585 查看
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();
}
{
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();
}
相关文章推荐
- Excel导入SQL时,如何动态获得Sheet的名字
- python 获取excel文件的所有sheet名字
- C#如何获取EXCEL所有的sheet表名?
- .Net 获取 Excel 的各个Sheet 名字
- C#可以获取Excel文件中Sheet的名字
- excel中遍历与同行其他列内容相同的其他sheet中的A列并获取对应行B列内容
- Excel中如何引用 「文件名」、「sheet 页」的名字
- Excel导入时,如何获取第一个Sheet名称
- 在excel中如何将一张表中有名字对应的数据对接到另一张表的有相同名字的后面(关于VLOOKUP函数)
- 省市县三级联动中如何取对应的名字,而非对应的数字value
- 如何在EXCEL SHEET中 动态添加控件
- 如何用javascript获取文本框,下拉框,单选框的对应值或者将值赋给它们?雪原虎 发布于:2007-10-22 00:32
- javascript如何通过访问者ip地址获取ip地址对应的物理地址API接口
- asp.net中, 如何在后台获取访问这个页面的用户的名字?
- Excel中sheet名字最大长度的坑
- 如何同时获取Map的构成对应关系的key和value
- 【C#】如何获取Dropdownlist空间已知值对应的Index,实现查询Dropdownlist值
- Excel加密的Sheet如何hack
- SQLServer获取Excel中所有Sheet
- 从DataSet 导出到Excel(是DataSet中的每个DataTable对应每个Sheet)