將Excel數(shù)據(jù)嵌入到VB中,,使他在VB的MDI窗體中,,看起來(lái)就像VB的一部分,同時(shí)我也可以用代碼對(duì)其進(jìn)行讀寫(xiě)
我用OLE把它嵌入到里面,,不過(guò)每次雙擊以后,,出來(lái)的Excel大小我無(wú)法控制 (我不想用對(duì)象的方式來(lái)操作Excel,因?yàn)槲乙丫庉嫳砀竦慕缑嫣峁┙o用戶(hù)) bas中:
Public XL As Excel.Application, xlHwnd As Long Public Declare Sub Sleep Lib "kernel32 " (ByVal dwMilliseconds As Long) Public Const WS_CAPTION As Long = &HC00000 Public Const SW_SHOW As Long = 5 Public Const WS_EX_APPWINDOW = &H40000 Public Const SW_SHOWMAXIMIZED = 3 Public Const GWL_STYLE As Long = -16 Public Const GW_HWNDNEXT = 2 Public Declare Function GetWindowThreadProcessId Lib "user32 " (ByVal hwnd As Long, lpdwProcessId As Long) As Long Public Declare Function GetParent Lib "user32 " (ByVal hwnd As Long) As Long Public Declare Function FindWindow Lib "user32 " Alias "FindWindowA " (ByVal lpClassName As String, ByVal lpWindowName As String) As Long Public Declare Function GetWindow Lib "user32 " (ByVal hwnd As Long, ByVal wCmd As Long) As Long Public Declare Function GetWindowText Lib "user32 " Alias "GetWindowTextA " (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long Public Declare Function SetParent Lib "user32 " (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long Public Declare Function SetWindowLong Lib "user32 " Alias "SetWindowLongA " (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long Public Declare Function GetWindowLong Lib "user32 " Alias "GetWindowLongA " (ByVal hwnd As Long, ByVal nIndex As Long) As Long Public Declare Function ShowWindow Lib "user32 " (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long Public Declare Function DrawMenuBar Lib "user32 " (ByVal hwnd As Long) As Long Public Const WS_SYSMENU = &H80000 Public Sub RemoveSysButton(ByVal hHwnd As Long) Dim lWnd As Long lWnd = GetWindowLong(hHwnd, GWL_STYLE) lWnd = lWnd And Not (WS_SYSMENU) lWnd = SetWindowLong(hHwnd, GWL_STYLE, lWnd) DrawMenuBar hHwnd End Sub Function InstanceToWnd(ByVal target_pid As Long) As Long Dim test_hwnd As Long Dim test_pid As Long Dim test_thread_id As Long test_hwnd = FindWindow(ByVal 0&, ByVal 0&) Do While test_hwnd <> 0 If GetParent(test_hwnd) = 0 Then test_thread_id = GetWindowThreadProcessId(test_hwnd, test_pid) If test_pid = target_pid Then InstanceToWnd = test_hwnd Exit Do End If End If test_hwnd = GetWindow(test_hwnd, GW_HWNDNEXT) Loop End Function Public Sub SetFormStyle(hwnd) Dim IStyle As Long IStyle = GetWindowLong(hwnd, GWL_STYLE) IStyle = IStyle And Not WS_CAPTION And Not WS_EX_APPWINDOW SetWindowLong hwnd, GWL_STYLE, IStyle ShowWindow hwnd, SW_SHOW DrawMenuBar hwnd End Sub form中: Set XL = CreateObject( "excel.application ") xlHwnd = FindWindow( "XLMAIN ", XL.Caption) oldHwnd = GetParent(xlHwnd) Call SetFormStyle(xlHwnd) l = SetParent(xlHwnd, Me.hwnd) XL.Workbooks.Open FileName:= "要打開(kāi)的文檔 " RemoveSysButton xlHwnd XL.WindowState = xlNormal XL.Height = Me.Height / 20 XL.Width = Me.Width / 20 XL.Top = 0 XL.Left = 0 大體就是這樣的,,在此基礎(chǔ)上再完善一下就達(dá)到要求了,。 |
|
來(lái)自: 昵稱(chēng)6703750 > 《我的圖書(shū)館》