.net 读取excel的sheet名字
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
1 protected string[] sheetfromexcel(string filepath)
2 {
3 OleDbConnection objConn = null;
4 DataTable dt = null;
5 string[] sheetName = null;
6 try
7 {
8 string connString =
9 "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+filepath+";Extended Properties=Excel 8.0;";
10 objConn = new OleDbConnection(connString);
11 objConn.Open();
12 dt = objConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
13
14 if (dt != null)
15 {
16 //string[] sheetName = new string[dt.Rows.Count];
17 sheetName = new string[dt.Rows.Count];
18 int i = 0;
19 foreach (DataRow row in dt.Rows)
20 {
21 sheetName[i] = row["TABLE_NAME"].ToString();
22 i++;
23 }
24 }
25 objConn.Close();
26 objConn.Dispose();
27 }
28 catch (Exception e1)
29 {
30 Response.Write(e1.Message);
31 }
32 return sheetName;
33
34 }
35
36
37