想鸟一样飞翔

专注于php开发。对c++也很有兴趣!!!

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

 Dim conn As ADODB.Connection
    Dim myrec As ADODB.Recordset
    Dim adopre As ADODB.Parameter
    Dim cmd As ADODB.Command
   
    Set conn = New ADODB.Connection
    Set myrec = New ADODB.Recordset
    Set adopre = New ADODB.Parameter
    Set cmd = New ADODB.Command
   
   

    conn.ConnectionString = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=DB_PurchaseOrder;Data Source=."
    conn.Open
    cmd.ActiveConnection = conn
    cmd.CommandType = adCmdStoredProc
    cmd.CommandText = "sp_recordset"
    Set adopre = cmd.CreateParameter("@bbb", adInteger, adParamInput)
    cmd.Parameters.Append adopre
    cmd.Parameters("@bbb").Value = "5"
    Set myrec = cmd.Execute()
          
       
    Dim myexcel As New Excel.Application
    Dim mybook As New Excel.Workbook
    Dim mysheet As New Excel.Worksheet
    Set mybook = myexcel.Workbooks.Add  '添加一个新的BOOK
    Set mysheet = mybook.Worksheets.Add  '添加一个新的SHEET
    myexcel.Visible = False
   
    mybook.Activate
   
    mysheet.Range 1, 6
   
    mysheet.Cells.CopyFromRecordset myrec
   
   
   
    mybook.SaveAs (App.Path & "\123.xls")  '保存文件
    'mybook.SaveCopyAs (App.Path & "\123.slx")   '保存文件
   ' myrec.Save (App.Path & "\1234.xls")  '保存文件
   
   
    myexcel.Quit

posted on 2007-08-13 12:04  redfox  阅读(556)  评论(0编辑  收藏  举报