我想把一个数据库中一张表中符合某些条件的若干列提取出来,保存在excel中,一种方法是vb+asp,还有没有其他方法不用到asp的?

解决方案 »

  1.   

    引用Excel Object 9.0组件
    Dim i As Integer
    Dim j As Integer
    Dim waijiaji As Excel.Application
    Dim x1book As Excel.Workbook
    Dim x1sheet As Excel.Worksheet
    On Error GoTo ine
    If Text2.Text = "" Then
       MsgBox ("请填写生产任务单号。")
       GoTo inerr
    End If
    Set waijiaji = CreateObject("Excel.Application")
    Set x1book = waijiaji.Workbooks.Open(App.Path + "\excel\磅单表1.xls")
    Set x1sheet = x1book.Worksheets(1)x1sheet.Cells(2, 2) = Text1(11).Text
    x1sheet.Cells(2, 12) = Text2.Text
    x1sheet.Cells(3, 2) = Text1(3).Text
    x1sheet.Cells(3, 7) = Text1(9).Text
    'x1sheet.Cells(3, 13) = Text1(11).Text
    x1sheet.Cells(4, 2) = Text1(0).Text
    x1sheet.Cells(5, 2) = Text1(6).Text
    x1sheet.Cells(5, 7) = Text1(7).Text
    x1sheet.Cells(5, 13) = Text1(8).Text
    x1sheet.Cells(6, 2) = Text1(14).Text
    x1sheet.Cells(7, 12) = Text1(10).Text
    '启动预览打印
    waijiaji.Visible = True
    waijiaji.Worksheets.PrintPreview
    waijiaji.AlertBeforeOverwriting = False
    waijiaji.DisplayAlerts = False
    Set x1book = Nothing
    waijiaji.Application.Quit
    GoTo inerr
    ine:
       MsgBox ("没有符合此要求的磅单。")
    inerr:
      

  2.   

    我以前是这样做的!将查询到的记录显示在MSFlexGrid控件中然后将显示的记录导入到Excel中!'*********************************************************
    '* 名称:OutDataToExcel
    '* 功能:将MsFlexGrid控件中显示的内容输出到Excel表格中进行打印
    '*********************************************************
    Public Sub OutDataToExcel(Flex As MSFlexGrid)    '导出至Excel
        Dim s As String
        Dim i As Integer
        Dim j As Integer
        Dim k As Integer
        On Error GoTo Ert
        Me.MousePointer = 11
        Dim Excelapp As Excel.Application
        Set Excelapp = New Excel.Application
        On Error Resume Next
        DoEvents
        Excelapp.SheetsInNewWorkbook = 1
        Excelapp.Workbooks.Add
        Excelapp.ActiveSheet.Cells(1, 3) = s
        Excelapp.Range("C1").Select
        Excelapp.Selection.Font.FontStyle = "Bold"
        Excelapp.Selection.Font.Size = 16
        With Flex
            k = .Rows
            For i = 0 To k - 1
                For j = 0 To .Cols - 1
                   DoEvents
                   Excelapp.ActiveSheet.Cells(3 + i, j + 1) = "'" & .TextMatrix(i, j)
                Next j
            Next i
        End With
        Me.MousePointer = 0
        Excelapp.Visible = True
        Excelapp.Sheets.PrintPreview       
    Ert:
        If Not (Excelapp Is Nothing) Then
            Excelapp.Quit
        End If
    End Sub