可以采用查獲詢的方法,下面是網上看來的
必须安装Execl2000工程引用execl9.0 object libraryDim rs As adodb.RecordsetDim xlApp As Excel.ApplicationDim xlBook As Excel.Workbook' Open the recordset.Set rs = db.OpenRecordset("SELECT _* FROM MyTable") '设置rs' Open the destination Excel workbook.Set xlApp = New Excel.ApplicationSet xlBook = xlApp.Workbooks.Open("D:\Book1.xls")' This is all it takes to copy the contents' of the recordset into the first worksheet' of Book1.xls.xlBook.Worksheets(1).Range("A1"). CopyFromRecordset rs '*****注意此语句***** execl2000' Clean up everything.xlBook.SavexlBook.Close FalsexlApp.Quitrs.Closedb.CloseSet xlBook = NothingSet xlApp = NothingSet rs = NothingEnd Sub
必须安装Execl2000工程引用execl9.0 object libraryDim rs As adodb.RecordsetDim xlApp As Excel.ApplicationDim xlBook As Excel.Workbook' Open the recordset.Set rs = db.OpenRecordset("SELECT _* FROM MyTable") '设置rs' Open the destination Excel workbook.Set xlApp = New Excel.ApplicationSet xlBook = xlApp.Workbooks.Open("D:\Book1.xls")' This is all it takes to copy the contents' of the recordset into the first worksheet' of Book1.xls.xlBook.Worksheets(1).Range("A1"). CopyFromRecordset rs '*****注意此语句***** execl2000' Clean up everything.xlBook.SavexlBook.Close FalsexlApp.Quitrs.Closedb.CloseSet xlBook = NothingSet xlApp = NothingSet rs = NothingEnd Sub
(col1,col2) select col1,col2 from opendatasource('SQLOLEDB','Data Source=';User ID=sa;Password=;').database