用ole嵌入来显示,自己模拟两个滚动条,打印预览和打印就调用excel,可以不让excel显示出来的,代码如下: Private Sub Command1_Click() 'oleTest.Action = 7 Dim xlApp As Excel.Application Set xlApp = New Excel.Application Set xlApp = CreateObject("Excel.Application") xlApp.WindowState = xlMaximized
xlApp.Visible = False Set xlBook = xlApp.Workbooks.Open(strPrintFileName) Set xlsheet = xlBook.Worksheets(1)
xlApp.Visible = True On Error Resume Next xlsheet.PrintPreview xlApp.Visible = False xlBook.Save xlApp.Quit
End Sub Private Sub Command2_Click() 'oleTest.Action = 7 Dim xlApp As Excel.Application Set xlApp = New Excel.Application Set xlApp = CreateObject("Excel.Application") xlApp.Visible = False Set xlBook = xlApp.Workbooks.Open(strPrintFileName) Set xlsheet = xlBook.Worksheets(1) On Error Resume Next xlsheet.PrintOut xlApp.Quit End SubPrivate Sub Command3_Click() Unload Me End SubPrivate Sub Form_Load()
oleTest.CreateLink strPrintFileName oleTest.SizeMode = 0 If oleTest.Width > picTest.ScaleWidth Then hslTest.Max = oleTest.Width - 2 hslTest.LargeChange = picTest.ScaleWidth hslTest.SmallChange = hslTest.Max - hslTest.LargeChange Else hslTest.Enabled = False oleTest.Width = picTest.ScaleWidth + 2 End If
If oleTest.Height > picTest.ScaleHeight Then vslTest.Max = oleTest.Height - 2 vslTest.LargeChange = picTest.ScaleHeight vslTest.SmallChange = vslTest.Max - vslTest.LargeChange Else vslTest.Enabled = False oleTest.Height = picTest.ScaleHeight + 2 End If
'MsgBox oleTest.Height & " " & picTest.ScaleHeight End SubPrivate Sub hslTest_Change() Call hslTest_Scroll End SubPrivate Sub hslTest_Scroll() oleTest.Left = (picTest.ScaleWidth - hslTest.Max) * (hslTest.Value / hslTest.Max) - 1
End SubPrivate Sub vslTest_Change() Call vslTest_Scroll
End SubPrivate Sub vslTest_Scroll() oleTest.Top = (picTest.ScaleHeight - vslTest.Max) * (vslTest.Value / vslTest.Max) - 1 End Sub
OLE1.SizeMode = vbOLESizeAuttoSize '调节对象大小使其正好充满OLE容器控件具体的看msdn
有嵌套 连接两种 任你选择
http://support.microsoft.com/default.aspx?scid=kb;en-us;311765
Private Sub Command1_Click()
'oleTest.Action = 7
Dim xlApp As Excel.Application
Set xlApp = New Excel.Application
Set xlApp = CreateObject("Excel.Application")
xlApp.WindowState = xlMaximized
xlApp.Visible = False
Set xlBook = xlApp.Workbooks.Open(strPrintFileName)
Set xlsheet = xlBook.Worksheets(1)
xlApp.Visible = True
On Error Resume Next
xlsheet.PrintPreview
xlApp.Visible = False
xlBook.Save
xlApp.Quit
End Sub
Private Sub Command2_Click()
'oleTest.Action = 7
Dim xlApp As Excel.Application
Set xlApp = New Excel.Application
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = False
Set xlBook = xlApp.Workbooks.Open(strPrintFileName)
Set xlsheet = xlBook.Worksheets(1)
On Error Resume Next
xlsheet.PrintOut
xlApp.Quit
End SubPrivate Sub Command3_Click()
Unload Me
End SubPrivate Sub Form_Load()
oleTest.CreateLink strPrintFileName
oleTest.SizeMode = 0
If oleTest.Width > picTest.ScaleWidth Then
hslTest.Max = oleTest.Width - 2
hslTest.LargeChange = picTest.ScaleWidth
hslTest.SmallChange = hslTest.Max - hslTest.LargeChange
Else
hslTest.Enabled = False
oleTest.Width = picTest.ScaleWidth + 2
End If
If oleTest.Height > picTest.ScaleHeight Then
vslTest.Max = oleTest.Height - 2
vslTest.LargeChange = picTest.ScaleHeight
vslTest.SmallChange = vslTest.Max - vslTest.LargeChange
Else
vslTest.Enabled = False
oleTest.Height = picTest.ScaleHeight + 2
End If
'MsgBox oleTest.Height & " " & picTest.ScaleHeight
End SubPrivate Sub hslTest_Change()
Call hslTest_Scroll
End SubPrivate Sub hslTest_Scroll()
oleTest.Left = (picTest.ScaleWidth - hslTest.Max) * (hslTest.Value / hslTest.Max) - 1
End SubPrivate Sub vslTest_Change()
Call vslTest_Scroll
End SubPrivate Sub vslTest_Scroll()
oleTest.Top = (picTest.ScaleHeight - vslTest.Max) * (vslTest.Value / vslTest.Max) - 1
End Sub