http://support.microsoft.com/default.aspx?scid=kb;en-us;Q246335http://support.microsoft.com/default.aspx?scid=kb;en-us;Q247412
http://support.microsoft.com/default.aspx?scid=kb;en-us;Q246335http://support.microsoft.com/default.aspx?scid=kb;en-us;Q247412
就有先把数据存到excel表中Dim xlApp As Excel.Application
On Error GoTo ErrHere
If MsgBox("详细打印", vbYesNo, "每日对帐单") = vbYes Then
Set xlApp = CreateObject("Excel.Application")
'Set xlApp = New Excel.Application
'激活EXCEL应用程序
'打开工作簿,strDestination为一个EXCEL报表文件Dim strSource, strDestination As StringstrSource = App.Path & "\RegFee.xls"'RegFee.xls就是一个模版文件strDestination = App.Path & "\Temp1.xls"FileCopy strSource, strDestinationxlApp.Visible = False '隐藏EXCEL应用程序窗口
Dim xlbook As Excel.Workbook
Set xlbook = xlApp.Workbooks.Open(strDestination)
Dim xlsheet As Worksheet
Set xlsheet = xlbook.Worksheets(1)xlsheet.Cells(1, 1) = "每日对帐单"
xlsheet.Cells(2, 1) = "操作员:" & ComboOP.Text & " 日期范围:" & Format(DTPStart(0).Value, "yyyy-mm-dd hh:mm:ss") & " - " & Format(DTPStart(1).Value, "yyyy-mm-dd hh:mm:ss")Dim i As Integer
For i = 0 To Me.MSHFlexGrid1.Rows - 1
xlsheet.Cells(3 + i, 1) = MSHFlexGrid1.TextMatrix(i, 0)
xlsheet.Cells(3 + i, 2) = MSHFlexGrid1.TextMatrix(i, 1)
xlsheet.Cells(3 + i, 3) = MSHFlexGrid1.TextMatrix(i, 2)
xlsheet.Cells(3 + i, 4) = MSHFlexGrid1.TextMatrix(i, 3)
xlsheet.Cells(3 + i, 5) = MSHFlexGrid1.TextMatrix(i, 4)
xlsheet.Cells(3 + i, 6) = MSHFlexGrid1.TextMatrix(i, 5)
xlsheet.Cells(3 + i, 7) = MSHFlexGrid1.TextMatrix(i, 6)
xlsheet.Cells(3 + i, 8) = MSHFlexGrid1.TextMatrix(i, 7)Next i
'将模版文件拷贝到一个临时文件
xlbook.Save '保存文件xlsheet.PrintOut '执行打印
xlApp.Quit '退出EXCEL
End IfExit SubErrHere:
MsgBox "打印出错!", vbExclamation, "详细打印"
End Sub
这个是把access中的数据通过vb导入到xls中,你看看吧
另外还有其他的http://202.98.116.66/amtd/taishan/index.html
这个是班主泰山的作品,不错的
主 题: 如何在VB中实现将数据导出到Excel??? 这个可能对你有点帮助