win32com.client(如何在Outlook中编辑联系人) [英] win32com.client (Howto edit Contacts in Outlook)

查看:128
本文介绍了win32com.client(如何在Outlook中编辑联系人)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编辑Outlook中的联系人。这样我就可以将我的地址簿中的数字

转移到我的手机上。我

遇到了以下代码片段,这使我能够联系到

至少列表。我不得不发现CdoDefaultFolderContacts

(虽然这是可以猜到的;我怎么能枚举win32com.client.constants?)。


我现在想要通过Outlook中的联系人修补我的

电子表格中的数据,并在我的

电子表格中有一个尚未进入联系人的条目中创建新联系人。


我在哪里可以找到API?我下载了OutlookSpy,但我不清楚

它是否可以显示数据的结构,也没有列出

对象的方法(一个联系人,一个文件夹)联系方式)我曾希望。


TIA,


比尔


class文件夹(对象) ):

def __init__(自我,文件夹):

self._folder =文件夹

def __getattr __(自我,属性):

返回getattr(self._folder,属性)

def __iter__(个体经营):



#NB你*必须*在这里收集对

#Messages集合的引用;否则GetFirst / Next

#每次都重置。



messages = self._folder.Messages

条消息= messages.GetFirst()

同时留言:

收益消息

message = messages.GetNext()


if __name__ ==''__ main__'':

import win32com.client

session = win32com.client.gencache.EnsureDispatch(" MAPI.Session" )

常量= win32com.client.constants

session.Logon(" Outlook")



#CdoDefaultFolderInbox

#CdoDefaultFolderSentItems

#CdoDefaultFolderContacts



contact_items =文件夹(session.GetDefaultFolder

(constants.CdoDefaultFolderContacts))

for contact_items中的消息:

打印消息

sys.exit(1 )

打印消息。主题

解决方案

Bill Davy写道:


我正在尝试编辑Outlook中的联系人。这样我就可以将我的地址簿中的数字

转移到我的手机上。我

遇到以下代码片段



---嘿!看起来很熟悉:)


这使我能够联系到

至少列表。我不得不四处寻找CdoDefaultFolderContacts

(虽然这是可以猜到的;我怎么能枚举win32com.client.constants?)。



这很简单:win32com.client.constants是一个小类,带有

a __dicts__属性(请注意s ;)这是一个字典列表,每个生成的库有一个

。所以你可以这样做:


< code>

import win32com.client


outlook = win32com.client.gencache.EnsureDispatch(" Outlook.Application")

outlook_constants = win32com.client.constants .__ dicts __ [0]


for k, v在outlook_constants.items():

print k," =>",v


< / code>
< blockquote class =post_quotes>
我现在想要通过我的

电子表格中的数据修补Outlook中的联系人,以及在我的
电子表格尚未进入联系人。



OK。


我在哪里可以找到API?



我建议:

http://msdn.microsoft.com/en-us/library/ms526861.aspx


和<

http://www.outlookcode.com /article.aspx?id=20



http://www.cdolive.com/cdo10.htm

TJG

Tim Golden < ma ** @ timgolden.me.ukwrote in message

news:ma ************************** *********** @ pytho n.org ...


Bill Davy写道:


>我正在尝试编辑Outlook中的联系人。这样我就可以将我的地址簿(即Excel电子表格)中的
号码传输到我的手机
手机上。我遇到了以下代码片段



---嘿!看起来很熟悉:)


>这使我能够联系到至少列表。我不得不四处寻找发现CdoDefaultFolderContacts(尽管它是可猜测的;我怎么能枚举win32com.client.constants?)。



嗯,这很简单:win32com.client.constants是一个小类,带有

a __dicts__属性(请注意s ;)这是一个字典列表,每个生成的库有一个

。所以你可以这样做:


< code>

import win32com.client


outlook = win32com.client.gencache.EnsureDispatch(" Outlook.Application")

outlook_constants = win32com.client.constants .__ dicts __ [0]


for k, v在outlook_constants.items():

print k," =>",v


< / code>
< blockquote class =post_quotes>
>我现在想要通过Outlook中的联系人修补我的电子表格中的数据,并在
我的条目中创建新的联系人尚未进入联系人的电子表格。



好​​的。


>我在哪里可以找到API?



我建议:

http://msdn.microsoft.com/en-us/library/ms526861.aspx


和<

http://www.outlookcode.com /article.aspx?id=20



http://www.cdolive.com/cdo10.htm


TJG



很棒。但是我对一个实验感到有些失望。在MSDN中,我发现

探索Outlook对象模型。这表明:

Outlook |工具|宏| VB编辑器|查看|对象浏览器


在那里我找到了ContactItems,并认为我是一个胜利者,但发现

amessage来自ContactFolder可能有Subject但它没有

FullName。此外,如果Python崩溃,它会让Outlook抱怨某人

正在访问它但已经消失,所以Outlook必须重新启动每个

时间。


但你已经提出了一些建议,所以谢谢。我有一个

的快速查看但是到目前为止还没找到主题作为

的成员/财产的消息/联系人。我会继续寻找。


Rgds,

Bill


" Bill Davy" < Bi ** @ SynectixLtd.com写信息

新闻:lP **************************** ** @ bt.com ...


" Tim Golden" < ma ** @ timgolden.me.ukwrote in message

news:ma ************************** *********** @ pytho n.org ...


> Bill Davy写道:


>>我正在尝试编辑Outlook中的联系人。这样我就可以将我的地址簿(即Excel电子表格)中的
号码传输到我的手机
手机上。我遇到了以下代码片段


---嘿!看起来很熟悉:)


>>这使我能够联系到至少列表。我不得不四处寻找发现CdoDefaultFolderContacts(尽管它是可猜测的;我怎么能枚举win32com.client.constants?)。


那个位很容易:win32com.client.constants是一个带有__dicts__属性的小类(注意s)这是一个列表字典,每个生成的库一个
。所以你可以这样做:

< code>
import win32com.client

outlook = win32com.client.gencache.EnsureDispatch(" Outlook。应用程序)
outlook_constants = win32com.client.constants .__ dicts __ [0]

for k,v in outlook_constants.items():
print k," => ",

< / code>


>>我现在想要通过Outlook中的联系人修补数据来自
我的电子表格,还有新的联系人,我的电子表格中有一个条目,但尚未进入联系人。


好的。


>>我在哪里可以找到API?


我建议:

http://msdn.microsoft.com/en-us/library/ms526861.aspx



< a rel =nofollowhref =http://www.outlookcode.com/article.aspx?id=20target =_ blank> http://www.outlookcode.com/article.aspx?id=20


http://www.cdolive.com/cdo10.htm

TJG




Brilliant。但是我对一个实验感到有些失望。在MSDN中我发现了b
探索Outlook对象模型。这表明:

Outlook |工具|宏| VB编辑器|查看|对象浏览器


在那里我找到了ContactItems并且估计我是一名获胜者,但发现

表示消息。来自ContactFolder可能有Subject但它没有

有FullName。此外,如果Python崩溃,它会让Outlook抱怨

有人正在访问它但已经消失,所以Outlook必须每次重启



但你已经提出了一些建议,所以谢谢。我快速看了一下

但是到目前为止还没找到主题作为会员/财产

的消息/联系人。我会继续寻找。


Rgds,

比尔



我一直在寻找并想到我当我在

Python Cookbook中找到了Receipe 10.16但是....


我更改了以下内容:


self.oOutlookApp = Dispatch(" Outlook.Application")

#self.oOutlookApp =

gencache.EnsureDispatch(" Outlook.Application")


因为gencache失败而且上周我一直在运行makepy(我只有一天

a周来看看这个)。


然后以下失败,因为(我发现)olFolderContacts不在

任何常量的词典中。


ofContacts = onMAPI.GetDefaultFolder( constants.olFolderContacts)


所以,遗憾的是,我将不得不把它搁置一个星期,然后继续使用

一些工作。我们将非常感激地接受任何想法。


TIA,

Bill


I am trying to edit Contacts in Outlook. This is so I can transfer numbers
from my address book which is an Excel spreadsheet to my mobile phone. I
came across the following snippet of code which enabled me to the contacts
at least list. I had to root around to discover CdoDefaultFolderContacts
(though it was guessable; how could I enumerate win32com.client.constants?).

I now want to work through the Contacts in Outlook patching in data from my
spreadsheet, and also making new contacts where there is an entry in my
spreadsheet which has not gone into Contacts already.

Where can I find the API? I downloaded OutlookSpy but it is not clear to me
that it can display the structure of the data, nor does it list methods for
objects (a Contact, a Folder of Contacts) that I had hoped.

TIA,

Bill

class Folder (object):
def __init__ (self, folder):
self._folder = folder
def __getattr__ (self, attribute):
return getattr (self._folder, attribute)
def __iter__ (self):
#
# NB You *must* collect a reference to the
# Messages collection here; otherwise GetFirst/Next
# resets every time.
#
messages = self._folder.Messages
message = messages.GetFirst ()
while message:
yield message
message = messages.GetNext ()

if __name__ == ''__main__'':
import win32com.client
session = win32com.client.gencache.EnsureDispatch ("MAPI.Session")
constants = win32com.client.constants
session.Logon ("Outlook")

#
# CdoDefaultFolderInbox
# CdoDefaultFolderSentItems
# CdoDefaultFolderContacts
#
contact_items = Folder (session.GetDefaultFolder
(constants.CdoDefaultFolderContacts))
for message in contact_items:
print message
sys.exit(1)
print message.Subject

解决方案

Bill Davy wrote:

I am trying to edit Contacts in Outlook. This is so I can transfer numbers
from my address book which is an Excel spreadsheet to my mobile phone. I
came across the following snippet of code

--- hey! that looks familiar :)

which enabled me to the contacts
at least list. I had to root around to discover CdoDefaultFolderContacts
(though it was guessable; how could I enumerate win32com.client.constants?).

Well that bit''s easy: win32com.client.constants is a small class with
a __dicts__ attribute (note the "s") which is a list of dictionaries, one
per generated library. So you can do something like this:

<code>
import win32com.client

outlook = win32com.client.gencache.EnsureDispatch ("Outlook.Application")
outlook_constants = win32com.client.constants.__dicts__[0]

for k, v in outlook_constants.items ():
print k, "=>", v

</code>

I now want to work through the Contacts in Outlook patching in data from my
spreadsheet, and also making new contacts where there is an entry in my
spreadsheet which has not gone into Contacts already.

OK.

Where can I find the API?

I recommend:

http://msdn.microsoft.com/en-us/library/ms526861.aspx

and

http://www.outlookcode.com/article.aspx?id=20

and

http://www.cdolive.com/cdo10.htm

TJG


"Tim Golden" <ma**@timgolden.me.ukwrote in message
news:ma*************************************@pytho n.org...

Bill Davy wrote:

>I am trying to edit Contacts in Outlook. This is so I can transfer
numbers from my address book which is an Excel spreadsheet to my mobile
phone. I came across the following snippet of code


--- hey! that looks familiar :)

>which enabled me to the contacts at least list. I had to root around to
discover CdoDefaultFolderContacts (though it was guessable; how could I
enumerate win32com.client.constants?).


Well that bit''s easy: win32com.client.constants is a small class with
a __dicts__ attribute (note the "s") which is a list of dictionaries, one
per generated library. So you can do something like this:

<code>
import win32com.client

outlook = win32com.client.gencache.EnsureDispatch ("Outlook.Application")
outlook_constants = win32com.client.constants.__dicts__[0]

for k, v in outlook_constants.items ():
print k, "=>", v

</code>

>I now want to work through the Contacts in Outlook patching in data from
my spreadsheet, and also making new contacts where there is an entry in
my spreadsheet which has not gone into Contacts already.


OK.

>Where can I find the API?


I recommend:

http://msdn.microsoft.com/en-us/library/ms526861.aspx

and

http://www.outlookcode.com/article.aspx?id=20

and

http://www.cdolive.com/cdo10.htm

TJG


Brilliant. But I was a bit disappointed by one experiment. In MSDN I found
"Exploring the Outlook Object Model". That suggested:
Outlook | Tools | Macros | VB Editor | View | Object Browser

There I found ContactItems and reckoned I was onto a winner, but found that
a "message" from the ContactFolder might have Subject but it did not have a
FullName. Also, if Python crashed, it left Outlook complaing that someone
was accessing it but had disappeaared so Outlook has to be restarted each
time.

But you have suggested some more things to look at so thanks. I have had a
quick look but have not so far even found "Subject" as a member/property of
a message/contact. I shall keep looking.

Rgds,
Bill


"Bill Davy" <Bi**@SynectixLtd.comwrote in message
news:lP******************************@bt.com...

"Tim Golden" <ma**@timgolden.me.ukwrote in message
news:ma*************************************@pytho n.org...

>Bill Davy wrote:

>>I am trying to edit Contacts in Outlook. This is so I can transfer
numbers from my address book which is an Excel spreadsheet to my mobile
phone. I came across the following snippet of code


--- hey! that looks familiar :)

>>which enabled me to the contacts at least list. I had to root around to
discover CdoDefaultFolderContacts (though it was guessable; how could I
enumerate win32com.client.constants?).


Well that bit''s easy: win32com.client.constants is a small class with
a __dicts__ attribute (note the "s") which is a list of dictionaries, one
per generated library. So you can do something like this:

<code>
import win32com.client

outlook = win32com.client.gencache.EnsureDispatch ("Outlook.Application")
outlook_constants = win32com.client.constants.__dicts__[0]

for k, v in outlook_constants.items ():
print k, "=>", v

</code>

>>I now want to work through the Contacts in Outlook patching in data from
my spreadsheet, and also making new contacts where there is an entry in
my spreadsheet which has not gone into Contacts already.


OK.

>>Where can I find the API?


I recommend:

http://msdn.microsoft.com/en-us/library/ms526861.aspx

and

http://www.outlookcode.com/article.aspx?id=20

and

http://www.cdolive.com/cdo10.htm

TJG



Brilliant. But I was a bit disappointed by one experiment. In MSDN I
found "Exploring the Outlook Object Model". That suggested:
Outlook | Tools | Macros | VB Editor | View | Object Browser

There I found ContactItems and reckoned I was onto a winner, but found
that a "message" from the ContactFolder might have Subject but it did not
have a FullName. Also, if Python crashed, it left Outlook complaing that
someone was accessing it but had disappeaared so Outlook has to be
restarted each time.

But you have suggested some more things to look at so thanks. I have had
a quick look but have not so far even found "Subject" as a member/property
of a message/contact. I shall keep looking.

Rgds,
Bill


I kept looking and thought I was saved when I found Receipe 10.16 in the
Python Cookbook but ....

I changed the following:

self.oOutlookApp = Dispatch("Outlook.Application")
#self.oOutlookApp =
gencache.EnsureDispatch("Outlook.Application")

Because gencache failed and I hade run makepy last week (I only get one day
a week to look at this).

Then the following failed because (as I found) olFolderContacts is not in
any of constants'' dictionaries.

ofContacts = onMAPI.GetDefaultFolder(constants.olFolderContacts )

So, sadly, I shall have to put this aside for another week and get on with
some work. Any thoughts would be gratefully accepted.

TIA,
Bill


这篇关于win32com.client(如何在Outlook中编辑联系人)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆