这个问题来自论坛提问,同理可以获得access等数据库的表结构信息。 using System; namespace ConsoleApplication11 { class Program { public static void Main() { getExcelFileInfo( @" c:a.xls " ); } private static void getExcelFileInfo( string Path) { string strConn = " Provider=Microsoft.Jet.OLEDB.4.0; " + " DataSource= " + Path + " ; " + " ExtendedProperties=Excel8.0; " ; System.Data.OleDb.OleDbConnectionconn = new System.Data.OleDb.OleDbConnection(strConn); conn.Open(); System.Data.DataTabletable = conn.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tables, null ); foreach (System.Data.DataRowdrow in table.Rows) { string TableName = drow[ " Table_Name " ].ToString(); Console.WriteLine(TableName + " : " ); System.Data.DataTabletableColumns = conn.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Columns, new object [] { null , null ,TableName, null } ); foreach (System.Data.DataRowdrowColumns in tableColumns.Rows) { string ColumnName = drowColumns[ " Column_Name " ].ToString(); Console.WriteLine( " " + ColumnName); } } Console.ReadKey( true ); } } }