用VB导数据到excel,提供一下代码,谢谢

解决方案 »

  1.   

    看看:
    http://community.csdn.net/Expert/topic/3572/3572323.xml?temp=.5341608
      

  2.   

    sql1 = "select isnull(CusCode,'客户')as cuscode, PMName as PMname,PasteBoardWidth as pasteboardwidth,Quantity as quantity,PasteBoardLength as pasteboardlength,UpOrDown as upordown,dissectnumber as dissectnumber,re as re into ##temp from " & dbcon & ".dbo.Mrp_MakingOrderSub " _
             & " where upordown = '" & Trim(Comboout.Text) & "' and makingordercode = '" & Trim(Lrtext(1).Text) & "'and state = 0"
             rs.Open sql1, conn
             Sqlstr = "insert into openrowset('Microsoft.Jet.OLEDB.4.0', 'd:\2\db.mdb ';'Admin'; '' ,导入) select cuscode,dissectnumber,pmname,pasteboardlength,pasteboardwidth,quantity,re,upordown from ##temp "
             'openrowset('Microsoft.Jet.OLEDB.4.0', 'd:\db.mdb ';'admin';'',导入)
             rs.Open Sqlstr, conn
             conn.Execute ("drop table ##temp")
      

  3.   

    '打开CSV文档
        ExpFNum = FreeFile
        Open ExpFName For Output As #ExpFNum
        ExpFileOpen = True
        
        '根据报表的结果写入Excel中
        For ii = 0 To MSFlexGrid.Rows - 1
            WriteLine = "," & Trim$(MSFlexGrid.TextMatrix(ii, 0))
            For jj = 1 To MSFlexGrid.Cols - 1
                WriteLine = WriteLine & "," & MSFlexGrid.TextMatrix(ii, jj)
            Next jj
            Print #ExpFNum, WriteLine
        Next ii'这样方便控制
      

  4.   

    你怎么不说把什么格式数据导入到excel中呢?
    这样很难帮到你......
      

  5.   

    Dim xlApp               As Excel.ApplicationSet xlApp = New Excel.Application
        Set xlApp = CreateObject("Excel.Application")
        
        Dim Iint As Integer
        xlApp.Visible = False '隐藏EXCEL应用程序窗口
        strSource = App.Path & "\Temp.xls"   'sale.xls就是一个模版文件
        strDestination = App.Path & "\ExcelFile\Temp.xls"
    LpN:
        
        FileCopy strSource, strDestination
        Set xlBook = xlApp.Workbooks.Open(strDestination)
        '打开工作簿,strDestination为一个EXCEL报表文件
        Set xlsheet = xlBook.Worksheets(1)
         
         
         '设定工作表
         'Fix((Rs.Fields.Count - 2) / 2) + 1
        xlsheet.Cells(1, 2) = PgInfo.CompanyName
        'xlsheet.Cells(1, Fix(Rs.Fields.Count - 2)) = "打印日期:" & Format(Date, "yyyy-mm-yy")
        
        xlsheet.Cells(2, 2) = gStrCardName & "汇总查询"
        xlsheet.Cells(2, Fix(Rs.Fields.Count - 1)) = "打印日期:" & Format(Date, "yyyy-mm-yy")
         
        
        xlsheet.Cells(3, 1) = mStrQueryTitle
        
        If mStrQueryTitle <> "" Then
        
        End If
        For Iint = 0 To Rs.Fields.Count - 1
            xlsheet.Cells(5, Iint + 1) = Rs.Fields.Item(Iint).Name
        
        Next Iint
        
        
        Iint = 5
        Do While Not Rs.EOF
              Iint = Iint + 1
              
              For intC = 0 To Rs.Fields.Count - 1
                Select Case Right(Rs.Fields.Item(intC).Name, 2)
                    Case "数量"
                        QtyCol = intC + 1
                        QtySum = QtySum + CCur(Rs.Fields(intC))
                        
                        xlsheet.Cells(Iint, intC + 1) = FormatNumber(Rs.Fields(intC), 0, vbTrue)
                        
                    Case "金额"
                        Select Case Rs.Fields.Item(intC).Name
                            Case "原有金额"
                                AmtCol(0) = intC + 1
                                AmtSum(0) = AmtSum(0) + CCur(Rs.Fields(intC))
                                
                            Case "消费金额"
                                AmtCol(1) = intC + 1
                                AmtSum(1) = AmtSum(1) + CCur(Rs.Fields(intC))
                                
                            Case "剩余金额"
                                AmtCol(2) = intC + 1
                                AmtSum(2) = AmtSum(2) + CCur(Rs.Fields(intC))
                                
                        End Select
    '                    xlsheet.Cells(Iint, IntC + 1) = "¥" & CStr(FormatNumber(Rs.Fields(IntC), 2, vbTrue))
                        
                        xlsheet.Cells(Iint, intC + 1) = FormatNumber(Rs.Fields(intC), 2, vbTrue)
                        
                    
                    Case Else
                        xlsheet.Cells(Iint, intC + 1) = Rs.Fields(intC)
                End Select
                
                
              
              Next intC
              Rs.MoveNext
        Loop
        
        Rs.Close
        
        xlsheet.Cells(Iint + 1, 1) = "合  计"
        If QtyCol > 0 Then xlsheet.Cells(Iint + 1, QtyCol) = FormatNumber(QtySum, 0, vbTrue)
        If AmtCol(0) > 0 Then xlsheet.Cells(Iint + 1, AmtCol(0)) = FormatNumber(AmtSum(0), 2, vbTrue)
        If AmtCol(1) > 0 Then xlsheet.Cells(Iint + 1, AmtCol(1)) = FormatNumber(AmtSum(1), 2, vbTrue)
        If AmtCol(2) > 0 Then xlsheet.Cells(Iint + 1, AmtCol(2)) = FormatNumber(AmtSum(2), 2, vbTrue)
        
        Me.MousePointer = 0xlApp.Visible = True
      

  6.   

    用 select into语句吧又快又简单
      

  7.   

    Dim Acdd As Access.Application
    Set Acdd = GetObject("D:\Program Files\Microsoft Visual Studio\VB98\*.mdb", "access.Application")
    Acdd.DoCmd.OutputTo acOutputTable, "表名", acFormatXLS, s & "\" & "表名.xls",trueSet Acdd = Nothing