Dim xlApp As Excel.Application
Set xlApp = New Excel.Application Set xlApp = CreateObject("Excel.Application")
‘激活EXCEL应用程序
xlApp.Visible = False ‘隐藏EXCEL应用程序窗口
Set xlBook = xlApp.Workbooks.add datPrimaryRS.Recordset.MoveFirst
‘datPrimaryRS为Data控件
If IsNull(datPrimaryRS.Recordset!姓名) = False Then
xlSheet.Cells(4, 2) = datPrimaryRS.Recordset!姓名
End If
If IsNull(datPrimaryRS.Recordset!性别) = False Then
xlSheet.Cells(4, 4) = datPrimaryRS.Recordset!性别
End If
If IsNull(datPrimaryRS.Recordset!民族) = False Then
xlSheet.Cells(4, 6) = datPrimaryRS.Recordset!民族
End If xlBook.Save ‘保存文件
xlSheet.PrintOut ‘执行打印
xlApp.Quit ‘退出EXCEL
Set xlApp = New Excel.Application Set xlApp = CreateObject("Excel.Application")
‘激活EXCEL应用程序
xlApp.Visible = False ‘隐藏EXCEL应用程序窗口
Set xlBook = xlApp.Workbooks.add datPrimaryRS.Recordset.MoveFirst
‘datPrimaryRS为Data控件
If IsNull(datPrimaryRS.Recordset!姓名) = False Then
xlSheet.Cells(4, 2) = datPrimaryRS.Recordset!姓名
End If
If IsNull(datPrimaryRS.Recordset!性别) = False Then
xlSheet.Cells(4, 4) = datPrimaryRS.Recordset!性别
End If
If IsNull(datPrimaryRS.Recordset!民族) = False Then
xlSheet.Cells(4, 6) = datPrimaryRS.Recordset!民族
End If xlBook.Save ‘保存文件
xlSheet.PrintOut ‘执行打印
xlApp.Quit ‘退出EXCEL
没定义。是不是还要定义一下呢。
我要每次grid中的都保存到一个xls中,如何实现啊
沒有定義﹐請問你是怎么解決這個問題的。盼在百忙之中抽點時間回復我﹐感謝﹗
[email protected]
我裝的是Office2000﹐這有沒有關系﹖謝謝回復。
把第二次实例化的删掉,即Set xlApp = CreateObject("Excel.Application")
如果还是不行的话,试试 Dim objExcelSample As Excel.Application
Dim objWorkbook As Excel.Workbook
Dim objWorkSheet As Excel.Worksheet
Set objExcelSample = New Excel.Application
Set objWorkbook = objExcelSample.Workbooks.Open("c:\book1.xls")
'前提是在C盘根目录下存在book1.xls文件
Set objWorkSheet = objWorkbook.Sheets("sheet1")
datPrimaryRS.Recordset.MoveFirst 'datPrimaryRS为Data控件
If IsNull(datPrimaryRS.Recordset!姓名) = False Then
objWorkSheet .Cells(4, 2) = datPrimaryRS.Recordset!姓名
End If
If IsNull(datPrimaryRS.Recordset!性别) = False Then
objWorkSheet .Cells(4, 4) = datPrimaryRS.Recordset!性别
End If
If IsNull(datPrimaryRS.Recordset!民族) = False Then
objWorkSheet .Cells(4, 6) = datPrimaryRS.Recordset!民族
End If objWorkSheet.PrintPreview '打印预览
objWorkSheet.PrintOut '打印
objWorkbook.Close
Set objExcelSample = Nothing
Set xl = CreateObject("Excel.document")
*
*
*
xl.SaveAs filename就不需要什么引用不引用Excel了。
但是通过OLE调用性能较差。
建议通过建立临时表……
最SELECT * INTO ……