1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
private string[] GetWorksheetNames(string excelFile)
{
OleDbConnection con = new OleDbConnection();
con.ConnectionString = "Data Source=" + excelFile +
";Provider=Microsoft.Jet.OLEDB.4.0" +
";Extended Properties=Excel 8.0";
con.Open();
DataTable tab = con.GetOleDbSchemaTable(
OleDbSchemaGuid.Tables,
new object[] {null, null, null, "TABLE"});
con.Close();
string[] tableNames = new string[tab.Rows.Count];
for (int i = 0; i < tab.Rows.Count; i++)
{
tableNames[i] = tab.Rows[i]["Table_Name"].ToString();
}
return tableNames;
}
|