使用 Python 打开 Outlook

发布于 2024-12-13 15:03:18 字数 337 浏览 2 评论 0原文

我正在尝试使用 Python 打开 Outlook,我得到了这个...

import win32com.client
ol = win32com.client.Dispatch("outlook.Application")

它打开了 Outlook,但我的问题是它在 Windows 的通知区域(时钟所在的位置)中打开它,但它不会在屏幕上打开它。我尝试了...

OL.visible= True

但收到错误消息,指出 Outlook 应用程序无法设置为可见。所以我的问题是如何将 Outlook 设为全屏或将其最大化至全屏?

I am trying to open Outlook with Python and I got this...

import win32com.client
ol = win32com.client.Dispatch("outlook.Application")

It opens Outlook but my probles is it opens it in the notification area of Windows (where the clock is) and it doesn't open it up on the screen. I tried a ...

OL.visible= True

But I get an error that Outlook application can't be set to visible. So my question is how can I bring Outlook for, or maximze it to a full screen?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

烟雨扶苏 2024-12-20 15:03:18

好吧,我发现这个工作起来很简单......

import os
os.startfile("outlook")

它使它成为一个大窗口,而不是一个最小化的窗口。

Ok I found this to work as simple as it was....

import os
os.startfile("outlook")

It makes it into a large window and mot a minimized one.

偏爱自由 2024-12-20 15:03:18

您见过这个问题吗?解决方案是从 shell 命令启动 Outlook,然后附加到正在运行的进程。这看起来很脏,但出于绝望,我对其他程序也做了同样的事情。我希望 MS Office 能够更好地与 COM 配合使用。

我想知道您是否可以执行类似于 MS 示例的操作

Set myOlApp = CreateObject("Outlook.Application")
Set myNameSpace = myOlApp.GetNameSpace("MAPI")
Set myFolder= _
    myNameSpace.GetDefaultFolder(olFolderInbox)
myFolder.Display

我没有安装 Outlook,所以无法测试任何内容。

Have you seen this SO question? The solution there was to start up Outlook from a shell command and then attach to the running process. It seems dirty, but I've done the same with other programs out of desperation. I would expect MS Office to play nicer with COM.

I wonder if you could do something similar to the MS example here.

Set myOlApp = CreateObject("Outlook.Application")
Set myNameSpace = myOlApp.GetNameSpace("MAPI")
Set myFolder= _
    myNameSpace.GetDefaultFolder(olFolderInbox)
myFolder.Display

I don't have Outlook installed so I can't test anything.

戈亓 2024-12-20 15:03:18

您还可以使用 psutil 检查 Outlook 是否正在运行

import psutil

def is_outlook_running():
    for p in psutil.process_iter(attrs=['pid', 'name']):
        if "OUTLOOK.EXE" in p.info['name']:
            print("Yes", p.info['name'], "is running")
            break
    else:
        print("No, Outlook is not running")
        os.startfile("outlook")
        print("Outlook is starting now...")

You could also check if Outlook is running using psutil

import psutil

def is_outlook_running():
    for p in psutil.process_iter(attrs=['pid', 'name']):
        if "OUTLOOK.EXE" in p.info['name']:
            print("Yes", p.info['name'], "is running")
            break
    else:
        print("No, Outlook is not running")
        os.startfile("outlook")
        print("Outlook is starting now...")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文