I am creating an appointment in Outlook through java code. here I can set new values to the fields in appointment. The code for it is
OleAutomation appointment = invoke(outlook, "CreateItem", 1).getAutomation();
appointment.setProperty(property(appointment, "Subject"), new Variant("Test"));
this code will set the subject field with the value "Test".
here i am using generic OLE mechanism "Variant" for passing data of different types via a common interface Now I want to know how to set a date for the appointment. Please help me..
Thanks in advance :)
As stated in my comment, the date in OLE are stored as the number of days since 1899-12-30. You can calculate that number easily. When you have it, pass-it to to the right OLE property using standard variant I think.
Unfortunately I don't have SWT installed here and can't test the code, but it should look something like that
public class Test {
static Calendar OLE_BASE_DATE = Calendar.getInstance();
static {
OLE_BASE_DATE.set(1899, 11, 30); // 1899-12-30
}
static double oleDateFormat(Calendar cal) {
long diff = cal.getTimeInMillis() - OLE_BASE_DATE.getTimeInMillis();
return diff / 86400000L;
}
public static void main(String[] args) {
// get outlook instance etc...
OleAutomation appointment = invoke(outlook, "CreateItem", 1).getAutomation();
appointment.setProperty(property(appointment, "Subject"), new Variant("Test"));
// compute the appointment start & stop
double todayAtNoon = oleDateFormat(Calendar.getInstance()) + 0.5;
double todayAt13_12 = oleDateFormat(Calendar.getInstance()) + 0.55;
// set the vars
appointment.setProperty(property(appointment, "Start"), new Variant(String.valueOf(todayAtNoon)));
appointment.setProperty(property(appointment, "End"), new Variant(String.valueOf(todayAt13_12)));
appointment.setProperty(property(appointment, "Location"), new Variant("At foo's"));
// do more stuff
}
}
More info on the automation of Outlook can be found here for a complete example in VB