看以下代码:

在返回的结果里回去 Table_Name列..

 DataTable _Table = GetExcelTableName(@"C:\1.xls");
            for (int i = 0; i != _Table.Rows.Count; i++)
            {
                MessageBox.Show(_Table.Rows[i]["Table_Name"].ToString());
            }

具体方法

/// <summary>  
       /// 获取EXCEL的表 表名字列   
       /// </summary>  
       /// <param name="p_ExcelFile">Excel文件</param>  
       /// <returns>数据表</returns>  
       public static DataTable GetExcelTableName(string p_ExcelFile)  
       {  
           try 
           {  
               if (System.IO.File.Exists(p_ExcelFile))  
               {  
                   OleDbConnection _ExcelConn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties=\"Excel 8.0\";Data Source=" + p_ExcelFile);  
                   _ExcelConn.Open();  
                   DataTable _Table = _ExcelConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);  
                   _ExcelConn.Close();  
                   return _Table;  
               }  
               return null;  
           }  
           catch 
           {  
               return null;  
           }  
       } 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-25
  • 2021-12-24
  • 2021-12-26
  • 2021-11-07
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-16
  • 2021-12-07
  • 2021-07-28
相关资源
相似解决方案