[python-win32] setting labels in outlook calendar

jjjanse jjjanse at home.nl
Sun Mar 16 21:01:09 CET 2008


After googling for a few hours I cannot find a solution to set a color on
outlook appointments.

 

In the following excerpt, an appointment is written, found and all
appointments are read back.

 

I used the makepy utility on the "Microsoft Outlook 11.0 Object Library" to
be able to browse

through this object lib and try things out. 

This caused the -well known-? problem of early binding where python
constructions like

 

for afspraak in afspraken:

    start = datetime.datetime.fromtimestamp (int (afspraak.Start))   

    subject = afspraak.Subject.encode("utf-8")

    print start, subject

 

used to work fine, suddenly were not recognized anymore and had to be
replaced by constructions

like stated below with GetFirst() and GetNext().

 

 

from win32com.client import constants

import win32com.client

import time

import datetime

 

print ('Writing a new appointment')

appointment = outlook.CreateItem(constants.olAppointmentItem)

appointment.Start = '2008-03-10 07:00:00'

appointment.Subject = 'Generated by Python'

appointment.Duration = 15

appointment.Location = 'perron 13a'

appointment.Save()

 

#finding this appointment

afspraken = namespace.GetDefaultFolder(9).Items

aap = afspraken.Find(u"[Subject] = Generated by Python")

print aap.Subject.encode("utf-8")

 

#reading all appointments

afspraken = namespace.GetDefaultFolder(9).Items

afspraken.Sort("[Start]") 

afspraken.IncludeRecurrences = "True"

#Possible columns are Subject, Location, Start, End, Recurrence Pattern,
Categories

afspraak = afspraken.GetFirst()

while afspraak:

    start = datetime.datetime.fromtimestamp (int (afspraak.Start))   

    subject = afspraak.Subject.encode("utf-8")

    if start == datetime.datetime(2008,03,10, 7,0):

        subject = afspraak.Subject.encode("utf-8")

        print subject

    afspraak = afspraken.GetNext()

    if start.year >nextYear:

        #avoid to loop until 2038 :-)

        break

 

So far, so good. But I could only find a VBA example for setting the label
on an appointment

by using a reference to a 'CDO 1.21' library which is not present on my
computer. Furthermore

I had a problem translating this example to python.

 

If u know a solution or example, please let me know,

Thnx in advance,

 

Joost Janse

 

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/python-win32/attachments/20080316/aa58fe21/attachment.htm 


More information about the python-win32 mailing list