主题:请问用c#.net怎样读取excel内部表名?
用c#.net读取excel内容代码:
string strCon = " Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source = c:\\book1.xls;Extended Properties=Excel 8.0" ;
OleDbConnection myConn = new OleDbConnection ( strCon ) ;
Excel.Application workbook = new Excel.WorkbookClass();
string strCom = " SELECT * FROM [Sheet1$] " ;
myConn.Open ( ) ;
OleDbDataAdapter myCommand = new OleDbDataAdapter ( strCom , myConn ) ;
DataSet myDataSet = new DataSet ( ) ;
myCommand.Fill ( myDataSet , "[Sheet1$]" );
myConn.Close ( ) ;
dataGrid1.DataMember= "[Sheet1$]" ;
dataGrid1.DataSource = myDataSet ;
Sheet1是已经知道的内部表名,但是如果不知道怎样查询所有内部表名?谢谢!
string strCon = " Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source = c:\\book1.xls;Extended Properties=Excel 8.0" ;
OleDbConnection myConn = new OleDbConnection ( strCon ) ;
Excel.Application workbook = new Excel.WorkbookClass();
string strCom = " SELECT * FROM [Sheet1$] " ;
myConn.Open ( ) ;
OleDbDataAdapter myCommand = new OleDbDataAdapter ( strCom , myConn ) ;
DataSet myDataSet = new DataSet ( ) ;
myCommand.Fill ( myDataSet , "[Sheet1$]" );
myConn.Close ( ) ;
dataGrid1.DataMember= "[Sheet1$]" ;
dataGrid1.DataSource = myDataSet ;
Sheet1是已经知道的内部表名,但是如果不知道怎样查询所有内部表名?谢谢!