How to hide COM object Dispatched from Python

后端 未结 1 714
执念已碎
执念已碎 2021-01-16 06:54

I\'m using COM in Python and I want the object to run in background - hidden. With Excel I do:

Import win32com.client 
Excel=win32com.client.Dispatch(\"Excel         


        
1条回答
  •  广开言路
    2021-01-16 07:12

    If you know your application title or class, you can hide it via ShowWindow:

    import win32com.client 
    import win32con
    import win32gui
    import time
    
    print "Start"
    excel = win32com.client.Dispatch("Excel.Application") 
    excel.Visible = 1   # Visible via automation
    time.sleep(2)
    hwnd = win32gui.FindWindow(None, "Microsoft Excel")  # Class or title
    print "Hide"
    win32gui.ShowWindow(hwnd, win32con.SW_HIDE) # Hide via Win32Api
    time.sleep(2)
    print "Show"
    win32gui.ShowWindow(hwnd, win32con.SW_SHOW) # Show via Win32Api
    time.sleep(2)
    
    ###
    

    HTH, Pablo

    0 讨论(0)
提交回复
热议问题