Private Sub mnu打印预览_Click()
Dim iRow As Long, iCol As Long
Dim xls As Excel.Application
Dim xlsWorkBook As Excel.Workbook
Dim xlsWorksheet As Excel.Worksheet
Set xls = CreateObject("Excel.Application")
If xls Is Nothing Then
MsgBox "请确认是否安装Excel软件!", vbOKOnly Or vbInformation, "提示"
Exit Sub
End If
xls.SheetsInNewWorkbook = 1
Set xlsWorkBook = xls.Workbooks.Add
Set xlsWorksheet = xlsWorkBook.Sheets(1)
For iCol = 0 To rsTemp.Fields.Count - 1
xlsWorksheet.Cells(1, iCol + 1) = rsTemp.Fields(iCol).Name
Next iCol
rsTemp.MoveFirst
Do Until rsTemp.EOF
For iCol = 0 To rsTemp.Fields.Count - 1 Step 1
xlsWorksheet.Cells(rsTemp.AbsolutePosition + 1, iCol + 1) = rsTemp.Fields(iCol).Value
Next iCol
rsTemp.MoveNext
Loop
xls.Visible = True '显示Excel
' xlsWorksheet.PrintPreview '打印预览
xls.DisplayAlerts = False '是否显示警告
' xls.Quit
End Sub
Dim iRow As Long, iCol As Long
Dim xls As Excel.Application
Dim xlsWorkBook As Excel.Workbook
Dim xlsWorksheet As Excel.Worksheet
Set xls = CreateObject("Excel.Application")
If xls Is Nothing Then
MsgBox "请确认是否安装Excel软件!", vbOKOnly Or vbInformation, "提示"
Exit Sub
End If
xls.SheetsInNewWorkbook = 1
Set xlsWorkBook = xls.Workbooks.Add
Set xlsWorksheet = xlsWorkBook.Sheets(1)
For iCol = 0 To rsTemp.Fields.Count - 1
xlsWorksheet.Cells(1, iCol + 1) = rsTemp.Fields(iCol).Name
Next iCol
rsTemp.MoveFirst
Do Until rsTemp.EOF
For iCol = 0 To rsTemp.Fields.Count - 1 Step 1
xlsWorksheet.Cells(rsTemp.AbsolutePosition + 1, iCol + 1) = rsTemp.Fields(iCol).Value
Next iCol
rsTemp.MoveNext
Loop
xls.Visible = True '显示Excel
' xlsWorksheet.PrintPreview '打印预览
xls.DisplayAlerts = False '是否显示警告
' xls.Quit
End Sub