Tasks and Calendars
Contents
[
Hide
Show
]It is possible to associate calendars with particular tasks in Microsoft Project. Aspose.Task supports this functionality.
Tasks with Calendars
The Task class exposes the Calendar property, used to set or get the calendar associated with a task. This property accepts or returns an object of com.aspose.tasks.Calendar class.
To create a calendar for a task in Microsoft Project:
- Open a project in Microsoft Project.
- On the Project menu, select Change Working Times, then Create New Calendar.
- To assign the calendar to a task, double-click the task in the Task Entry form.
- Select the Advanced tab.
The Change Working Time dialog showing a custom-made calendar
Setting Task Calendar
Create a standard calendar and create a task. Assign the Calendar to the task.
1// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
2// The path to the documents directory.
3String dataDir = Utils.getDataDir(TasksAndCalendars.class);
4
5Project project = new Project();
6Task tsk = project.getRootTask().getChildren().add("Task1");
7// add a standard calendar
8Calendar cal = project.getCalendars().add("TaskCal1");
9
10tsk.set(Tsk.CALENDAR, cal);
Getting Task Calendar
Get a task calendar by traversing the tasks in a project.
1// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
2// The path to the documents directory.
3String dataDir = Utils.getDataDir(TasksAndCalendars.class);
4
5// create a project instance
6Project prj = new Project(dataDir + "project5.mpp");
7
8// Declare ChildTasksCollector class object
9ChildTasksCollector collector = new ChildTasksCollector();
10
11// Use TaskUtils to get all children tasks in RootTask
12TaskUtils.apply(prj.getRootTask(), collector, 0);
13
14// Parse all the recursive children
15for (Task tsk : collector.getTasks()) {
16 Calendar tskCal = tsk.get(Tsk.CALENDAR);
17 System.out.println("Task calendar name:" + tskCal.getName());
18}