C# 取Excel Sheet列表
程序员文章站
2022-07-13 15:17:41
...
C# 取Excel Sheet列表
List<SheetName> GetSheetNames(OleDbConnection conn)
{
List<SheetName> sheetNames = new List<SheetName>();
if (conn.State != ConnectionState.Open)
{
conn.Open();
}
DataTable excelSchema = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
foreach (DataRow row in excelSchema.Rows)
{
if (!row["TABLE_NAME"].ToString().Contains("FilterDatabase"))//排除FilterDatabase :如果有做筛选会产生隐藏的表
{
sheetNames.Add(new SheetName() { sheetName = row["TABLE_NAME"].ToString(), sheetType = row["TABLE_TYPE"].ToString(), sheetCatalog = row["TABLE_CATALOG"].ToString(), sheetSchema = row["TABLE_SCHEMA"].ToString() });
}
}
//conn.Close();
return sheetNames;
}
class SheetName
{
public string sheetName { get; set; }
public string sheetType { get; set; }
public string sheetCatalog { get; set; }
public string sheetSchema { get; set; }
}
上一篇: 这个布林带的均值回归交易策略,回测收益率把我给吓傻了
下一篇: 开源的13个优秀学习项目