你用的是ADO吗??
如果是ADO,可以用Excel_sheet_object.copyfromrecordset
然后用Excel_object.saveas Filename 就可以了

解决方案 »

  1.   

    如果你的算法不是复杂 就用VB自带的报表 也可用第三方控件 若然一定想引用OFFICE的 引用ACCESS比EXCEL还好 最起码关闭引用后 ACCESS会从内存中退出 但引用EXCEL 我发觉它仍在内存中驻存
      

  2.   

    呵呵,你有没有试试先用宏把你希望的操作先录制下来,然后把他转变成vb代码.作为一个过程在vb中引用这个工程.当然你要注意excel对象在vb中引用的必须步骤.
    然后在对一些地方做稍微的改动.就可以用了.
    我原来在单位上写了一个盘点表程序,就是把数据写入到excel里,并且把打印格式(其中也有内似你的要求)都写好了,就是这样干的.但要注意一定要设置一台默认的打印机(只要安装了驱动程序就行了),程序中也要指定.可惜原代码丢失了,不然可以给你,不好意思
      

  3.   

    '第一行为标题
        Range("A1").Select
        ActiveCell.FormulaR1C1 = "标题"
        '第二行为一横线
        Range("A2").Select
        Application.CommandBars("Drawing").Visible = True
        ActiveSheet.Shapes.AddLine(2.25, 22.5, 270#, 22.5).Select
        '第三到十四行是要打印的表格, 四周画上网格线
        Range("A3:E14").Select
        Selection.Borders(xlDiagonalDown).LineStyle = xlNone
        Selection.Borders(xlDiagonalUp).LineStyle = xlNone
        With Selection.Borders(xlEdgeLeft)
            .LineStyle = xlContinuous
            .Weight = xlThin
            .ColorIndex = xlAutomatic
        End With
        With Selection.Borders(xlEdgeTop)
            .LineStyle = xlContinuous
            .Weight = xlThin
            .ColorIndex = xlAutomatic
        End With
        With Selection.Borders(xlEdgeBottom)
            .LineStyle = xlContinuous
            .Weight = xlThin
            .ColorIndex = xlAutomatic
        End With
        With Selection.Borders(xlEdgeRight)
            .LineStyle = xlContinuous
            .Weight = xlThin
            .ColorIndex = xlAutomatic
        End With
        With Selection.Borders(xlInsideVertical)
            .LineStyle = xlContinuous
            .Weight = xlThin
            .ColorIndex = xlAutomatic
        End With
        With Selection.Borders(xlInsideHorizontal)
            .LineStyle = xlContinuous
            .Weight = xlThin
            .ColorIndex = xlAutomatic
        End With
        '第十五行为页码
        Range("D15").Select
        ActiveCell.FormulaR1C1 = "页码:1"上面的程序只是生成了一页表格(Excel宏程序)
    至于你要从Recordset中取得的数据可以通过循环写入表格中
    while not rs.eof
      Range(row&col).select
      ActiveCell.FormulaR1C1 = rs(fieldname)
      rs.movenext
    wend