请在VB中使用 excel 作过报表的大虾进来看看 你用的是ADO吗??如果是ADO,可以用Excel_sheet_object.copyfromrecordset然后用Excel_object.saveas Filename 就可以了 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 如果你的算法不是复杂 就用VB自带的报表 也可用第三方控件 若然一定想引用OFFICE的 引用ACCESS比EXCEL还好 最起码关闭引用后 ACCESS会从内存中退出 但引用EXCEL 我发觉它仍在内存中驻存 呵呵,你有没有试试先用宏把你希望的操作先录制下来,然后把他转变成vb代码.作为一个过程在vb中引用这个工程.当然你要注意excel对象在vb中引用的必须步骤.然后在对一些地方做稍微的改动.就可以用了.我原来在单位上写了一个盘点表程序,就是把数据写入到excel里,并且把打印格式(其中也有内似你的要求)都写好了,就是这样干的.但要注意一定要设置一台默认的打印机(只要安装了驱动程序就行了),程序中也要指定.可惜原代码丢失了,不然可以给你,不好意思 '第一行为标题 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.movenextwend 自动回帖机征集 求Setup Factory中文指南 高分求助,在2003里createobject出错 为什么addressof 出错 怎么给窗体加上滚动条(上下滚动)-着急 在VB中调用VC写的DLL文件出错? 哪有Install Shield下载? 如何在IE右键菜单中添加菜单项? 重金,高手请进 一个非常简单的问题,请各位指点,非常感谢!!! set text1.datasource=data1时出错了,提示没有这个属性 在保存工程时,有时会提示保存组文件,组文件是什么东西????????
然后在对一些地方做稍微的改动.就可以用了.
我原来在单位上写了一个盘点表程序,就是把数据写入到excel里,并且把打印格式(其中也有内似你的要求)都写好了,就是这样干的.但要注意一定要设置一台默认的打印机(只要安装了驱动程序就行了),程序中也要指定.可惜原代码丢失了,不然可以给你,不好意思
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