我正在使用office .NET框架在Outlook中创建约会。创建约会的代码如下所示:
private void createCalendarEvent(DateTime start, DateTime end, String dept, String subj, String subjType, String room)
{
AppointmentItem apt = (AppointmentItem)OLapp.CreateItem(OlItemType.olAppointmentItem);
apt.Start = start;
apt.End = end;
apt.Subject = subj + " - " + subjType;
apt.Body = "Subject: " + subj + " (" + subjType + ")"
+ "\nDepartment: " + dept
+ "\nRoom: " + room
+ "\n\nCreated by " + this.Text
+ "\n On " + DateTime.Now.ToLongDateString() + " At " + DateTime.Now.ToLongTimeString();
apt.Location = room;
apt.Categories = subj;
apt.Save();
}
这很好用,但我设置的类别没有与之关联的颜色。我希望outlook中的约会以不同的颜色显示,具体取决于类别集。有什么方法我可以手动设置类别颜色?或者甚至更好,一种让框架自动为我选择类别颜色的方法吗?
答案 0 :(得分:1)
this question的答案涉及类别。具体来说,这里有一些代码(VB.net,但很容易转换),将创建一个深橄榄类:
Private Shared ReadOnly CATEGORY_TEST As String = "Custom Overdue Activity"
' This method checks if our custom category exists, and creates it if it doesn't.
Private Sub SetupCategories()
Dim categoryList As Categories = Application.Session.Categories
For i As Integer = 1 To categoryList.Count
Dim c As Category = categoryList(i)
If c.Name.Equals(CATEGORY_TEST) Then
Return
End If
Next
categoryList.Add(CATEGORY_TEST, Outlook.OlCategoryColor.olCategoryColorDarkOlive)
End Sub
在Outlook中或在代码中创建类别时,在上面的代码中设置类别颜色。