i have an excel with multi-sheets that i want to import
the code is fairly simple and basic and should work
but my sheetnames keep coming back as \"_xlnm#_Filter
Excel creates a hidden sheet each time you filter on a sheet and all though this sheet should not be available when retrieving the sheet names. Here is a piece of code that will help you get the sheet names using System.Data.OleDb:
class Retriever
{
public 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"))
{
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; }
}
Please get back to me if you're having any kind of issues with this.
Have fun!