Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Aspose.Tasks for Java
This Gist contains code snippets from examples of Aspose.Tasks for Java.
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(AddRemoveCalendarExceptions.class);
Project project = new Project(dataDir + "input.mpp");
// Remove an exception
Calendar cal = project.getCalendars().toList().get(0);
if (cal.getExceptions().getCount() > 1) {
CalendarException exc = cal.getExceptions().toList().get(0);
cal.getExceptions().remove(exc);
}
// Add an exception
CalendarException calExc = new CalendarException();
java.util.Calendar calObject = java.util.Calendar.getInstance();
calObject.set(2009, 1, 1, 0, 0, 0);
calExc.setFromDate(calObject.getTime());
calObject.set(2009, 1, 3, 0, 0, 0);
calExc.setToDate(calObject.getTime());
cal.getExceptions().add(calExc);
// Display exceptions
for (CalendarException calExc1 : cal.getExceptions()) {
System.out.println("From" + calExc1.getFromDate().toString());
System.out.println("To" + calExc1.getToDate().toString());
}
// The path to the documents directory.
String dataDir = Utils.getDataDir(AddRemoveCalendarExceptions.class);
Project project = new Project(dataDir + "input.mpp");
//Remove an exception
Calendar cal = project.getCalendars().toList().get(0);
if (cal.getExceptions().size() > 1)
{
CalendarException exc = cal.getExceptions().toList().get(0);
cal.getExceptions().remove(exc);
}
//Add an exception
CalendarException calExc = new CalendarException();
java.util.Calendar calObject = java.util.Calendar.getInstance();
calObject.set(2009, 1, 1, 0, 0, 0);
calExc.setFromDate(calObject.getTime());
calObject.set(2009, 1, 3, 0, 0, 0);
calExc.setToDate(calObject.getTime());
cal.getExceptions().add(calExc);
//Display exceptions
for(CalendarException calExc1:cal.getExceptions())
{
System.out.println("From" + calExc1.getFromDate().toString());
System.out.println("To" + calExc1.getToDate().toString());
}
// The path to the documents directory.
String dataDir = Utils.getDataDir(DefineWeekdaysForExceptions.class);
//Create a project instance
Project project = new Project();
//Define Calendar
Calendar cal = project.getCalendars().add("Calendar1");
//Define week days exception for Christmas
CalendarException except = new CalendarException();
except.setEnteredByOccurrences(false);
java.util.Calendar calObject = java.util.Calendar.getInstance();
calObject.set(2009, 12, 24, 0, 0, 0);
except.setFromDate(calObject.getTime());
calObject.set(2009, 12, 31, 23, 59, 0);
except.setToDate(calObject.getTime());
except.setType(CalendarExceptionType.Daily);
except.setDayWorking(false);
cal.getExceptions().add(except);
//Save the Project
project.save(dataDir + "Project.Xml", SaveFileFormat.XML);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(DefineWeekdaysForExceptions.class);
// Create a project instance
Project project = new Project();
// Define Calendar
Calendar cal = project.getCalendars().add("Calendar1");
// Define week days exception for Christmas
CalendarException except = new CalendarException();
except.setEnteredByOccurrences(false);
java.util.Calendar calObject = java.util.Calendar.getInstance();
calObject.set(2009, 12, 24, 0, 0, 0);
except.setFromDate(calObject.getTime());
calObject.set(2009, 12, 31, 23, 59, 0);
except.setToDate(calObject.getTime());
except.setType(CalendarExceptionType.Daily);
except.setDayWorking(false);
cal.getExceptions().add(except);
// Save the Project
project.save(dataDir + "Project.Xml", SaveFileFormat.XML);
CalendarException except = new CalendarException();
except.setEnteredByOccurrences(true);
except.setOccurrences(5);
except.setType(CalendarExceptionType.YearlyByDay);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(HandleOccurrences.class);
CalendarException except = new CalendarException();
except.setEnteredByOccurrences(true);
except.setOccurrences(5);
except.setType(CalendarExceptionType.YearlyByDay);
// The path to the documents directory.
String dataDir = Utils.getDataDir(RetrieveCalendarExceptions.class);
Project project = new Project(dataDir + "file.mpp");
for(Calendar cal:project.getCalendars())
{
for(CalendarException calExc: cal.getExceptions())
{
System.out.println("From: " + calExc.getFromDate().toString()) ;
System.out.println("To: " + calExc.getToDate().toString()) ;
}
}
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(RetrieveCalendarExceptions.class);
Project project = new Project(dataDir + "file.mpp");
for (Calendar cal : project.getCalendars()) {
for (CalendarException calExc : cal.getExceptions()) {
System.out.println("From: " + calExc.getFromDate().toString());
System.out.println("To: " + calExc.getToDate().toString());
}
}
// The path to the documents directory.
String dataDir = Utils.getDataDir(CalendarProperties.class);
long OneSec = 10000000;// microsecond * 10
long OneMin = 60 * OneSec;
long OneHour = 60 * OneMin;
Project project = new Project(dataDir + "prj.mpp");
for (Calendar cal : project.getCalendars()) {
if (cal.getName().toString() != null) {
for (WeekDay wd : cal.getWeekDays()) {
double ts = wd.getWorkingTime();
double time = ts / (OneHour);
System.out.println("Day Type" + wd.getDayType() + "Hours" + ts);
}
System.out.println("Base Calendar : ");
if (cal.isBaseCalendar())
System.out.println("Self");
else
System.out.println(cal.getBaseCalendar().getName());
System.out.println("UID : " + cal.getUid());
System.out.println("Name : " + cal.getName());
}
}
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(CalendarProperties.class);
long OneSec = 10000000;// microsecond * 10
long OneMin = 60 * OneSec;
long OneHour = 60 * OneMin;
Project project = new Project(dataDir + "prj.mpp");
for (Calendar cal : project.getCalendars()) {
if (cal.getName().toString() != null) {
for (WeekDay wd : cal.getWeekDays()) {
double ts = wd.getWorkingTime();
double time = ts / (OneHour);
System.out.println("Day Type" + wd.getDayType() + "Hours" + ts);
}
System.out.println("Base Calendar : ");
if (cal.isBaseCalendar())
System.out.println("Self");
else
System.out.println(cal.getBaseCalendar().getName());
System.out.println("UID : " + cal.getUid());
System.out.println("Name : " + cal.getName());
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(CreateCalendar.class);
// Create a project instance
Project prj = new Project();
// Define Calendar
Calendar cal1 = prj.getCalendars().add("no info");
Calendar cal2 = prj.getCalendars().add("no name");
Calendar cal3 = prj.getCalendars().add("cal3");
// Save the Project
prj.save(dataDir + "Project.Xml", SaveFileFormat.XML);
// The path to the documents directory.
String dataDir = Utils.getDataDir(CreateCalendar.class);
// Create a project instance
Project prj = new Project();
// Define Calendar
Calendar cal1 = prj.getCalendars().add("no info");
Calendar cal2 = prj.getCalendars().add("no name");
Calendar cal3 = prj.getCalendars().add("cal3");
prj.getCalendars().add(cal1);
prj.getCalendars().add(cal2);
prj.getCalendars().add(cal3);
// Save the Project
prj.save(dataDir + "Project.Xml", SaveFileFormat.XML);
// Display result of conversion.
System.out.println("Process completed Successfully");
// The path to the documents directory.
String dataDir = Utils.getDataDir(DefineWeekdays.class);
//Create a project instance
Project prj = new Project();
//Define Calendar
Calendar cal = prj.getCalendars().add("Calendar1");
//Add working days Monday through Thursday with default timings
cal.getWeekDays().add(WeekDay.createDefaultWorkingDay(DayType.Monday));
cal.getWeekDays().add(WeekDay.createDefaultWorkingDay(DayType.Tuesday));
cal.getWeekDays().add(WeekDay.createDefaultWorkingDay(DayType.Wednesday));
cal.getWeekDays().add(WeekDay.createDefaultWorkingDay(DayType.Thursday));
cal.getWeekDays().add(new WeekDay(DayType.Saturday));
cal.getWeekDays().add(new WeekDay(DayType.Sunday));
//Set Friday as short working day
WeekDay myWeekDay = new WeekDay(DayType.Friday);
//Sets working time. Only time part of DateTime is important
WorkingTime wt1 = new WorkingTime();
java.util.Calendar calTime = java.util.Calendar.getInstance();
calTime.set(1,1,1,9,0,0);
Date date = calTime.getTime();
wt1.setFromTime(date);
calTime.set(1,1,1,12,0,0);
date = calTime.getTime();
wt1.setToTime(date);
WorkingTime wt2 = new WorkingTime();
calTime.set(1,1,1,13,0,0);
date = calTime.getTime();
wt2.setFromTime(date);
calTime.set(1,1,1,16,0,0);
date = calTime.getTime();
wt2.setToTime(date);
myWeekDay.getWorkingTimes().add(wt1);
myWeekDay.getWorkingTimes().add(wt2);
myWeekDay.setDayWorking(true);
cal.getWeekDays().add(myWeekDay);
//Save the Project
prj.save(dataDir + "Project.Xml", SaveFileFormat.XML);
//Display result of conversion.
System.out.println("Process completed Successfully");
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(DefineWeekdays.class);
// Create a project instance
Project prj = new Project();
// Define Calendar
Calendar cal = prj.getCalendars().add("Calendar1");
// Add working days monday through thursday with default timings
cal.getWeekDays().add(WeekDay.createDefaultWorkingDay(DayType.Monday));
cal.getWeekDays().add(WeekDay.createDefaultWorkingDay(DayType.Tuesday));
cal.getWeekDays().add(WeekDay.createDefaultWorkingDay(DayType.Wednesday));
cal.getWeekDays().add(WeekDay.createDefaultWorkingDay(DayType.Thursday));
cal.getWeekDays().add(new WeekDay(DayType.Saturday));
cal.getWeekDays().add(new WeekDay(DayType.Sunday));
// Set friday as short working day
WeekDay myWeekDay = new WeekDay(DayType.Friday);
// Sets working time. Only time part of DateTime is important
WorkingTime wt1 = new WorkingTime();
java.util.Calendar calTime = java.util.Calendar.getInstance();
calTime.set(1, 1, 1, 9, 0, 0);
Date date = calTime.getTime();
wt1.setFromTime(date);
calTime.set(1, 1, 1, 12, 0, 0);
date = calTime.getTime();
wt1.setToTime(date);
WorkingTime wt2 = new WorkingTime();
calTime.set(1, 1, 1, 13, 0, 0);
date = calTime.getTime();
wt2.setFromTime(date);
calTime.set(1, 1, 1, 16, 0, 0);
date = calTime.getTime();
wt2.setToTime(date);
myWeekDay.getWorkingTimes().add(wt1);
myWeekDay.getWorkingTimes().add(wt2);
myWeekDay.setDayWorking(true);
cal.getWeekDays().add(myWeekDay);
// Save the Project
prj.save(dataDir + "Project.Xml", SaveFileFormat.XML);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(GetWorkingHours.class);
long OneSec = 10000000;// microsecond * 10
long OneMin = 60 * OneSec;
long OneHour = 60 * OneMin;
Project project = new Project(dataDir + "BaselineTask.mpp");
Task task = project.getRootTask().getChildren().getById(1);
Calendar taskCalendar = task.get(Tsk.CALENDAR);
java.util.Calendar calStartDate = java.util.Calendar.getInstance();
calStartDate.setTime(task.get(Tsk.START));
java.util.Calendar calEndDate = java.util.Calendar.getInstance();
calEndDate.setTime(task.get(Tsk.FINISH));
java.util.Calendar tempDate = java.util.Calendar.getInstance();
tempDate = calStartDate;
Resource resource = project.getResources().getById(1);
Calendar resourceCalendar = resource.get(Rsc.CALENDAR);
// TimeSpan timeSpan;
long timeSpan = 0;
// Get Duration in Minutes
double durationInMins = 0;
while (tempDate.before(calEndDate)) {
if (taskCalendar.isDayWorking(tempDate.getTime()) && resourceCalendar.isDayWorking(tempDate.getTime())) {
timeSpan = (long) taskCalendar.getWorkingHours(tempDate.getTime());
durationInMins = durationInMins + (timeSpan / OneMin);
}
tempDate.add(java.util.Calendar.DATE, 1);
}
tempDate.setTime(task.get(Tsk.START));
// Get Duration in Hours
double durationInHours = 0;
while (tempDate.before(calEndDate)) {
if (taskCalendar.isDayWorking(tempDate.getTime()) && resourceCalendar.isDayWorking(tempDate.getTime())) {
timeSpan = (long) taskCalendar.getWorkingHours(tempDate.getTime());
durationInHours = durationInHours + (timeSpan / OneHour);
}
tempDate.add(java.util.Calendar.DATE, 1);
}
tempDate.setTime(task.get(Tsk.START));
// Get Duration in Days
double durationInDays = 0;
while (tempDate.before(calEndDate)) {
if (taskCalendar.isDayWorking(tempDate.getTime()) && resourceCalendar.isDayWorking(tempDate.getTime())) {
timeSpan = (long) taskCalendar.getWorkingHours(tempDate.getTime());
if ((timeSpan / OneHour) > 0)
durationInDays = durationInDays + (timeSpan / OneHour / 8.0);
}
tempDate.add(java.util.Calendar.DATE, 1);
}
tempDate = calStartDate;
System.out.println("Duration in Minutes = " + durationInMins);
System.out.println("Duration in Hours = " + durationInHours);
System.out.println("Duration in Days = " + durationInDays);
// The path to the documents directory.
String dataDir = Utils.getDataDir(GetWorkingHours.class);
long OneSec = 10000000;//microsecond * 10
long OneMin = 60 * OneSec;
long OneHour = 60 * OneMin;
Project project = new Project(dataDir + "BaselineTask.mpp");
Task task = project.getRootTask().getChildren().getById(1);
Calendar taskCalendar = task.get(Tsk.CALENDAR);
java.util.Calendar calStartDate = java.util.Calendar.getInstance();
calStartDate.setTime(task.get(Tsk.START));
java.util.Calendar calEndDate = java.util.Calendar.getInstance();
calEndDate.setTime(task.get(Tsk.FINISH));
java.util.Calendar tempDate = java.util.Calendar.getInstance();
tempDate = calStartDate;
Resource resource = project.getResources().getById(1);
Calendar resourceCalendar = resource.get(Rsc.CALENDAR);
//TimeSpan timeSpan;
long timeSpan = 0;
//Get Duration in Minutes
double durationInMins = 0;
while (tempDate.before(calEndDate))
{
if (taskCalendar.isDayWorking(tempDate.getTime()) && resourceCalendar.isDayWorking(tempDate.getTime()))
{
timeSpan = (long) taskCalendar.getWorkingHours(tempDate.getTime());
durationInMins = durationInMins + (timeSpan / OneMin);
}
tempDate.add(java.util.Calendar.DATE, 1);
}
tempDate.setTime(task.get(Tsk.START));
//Get Duration in Hours
double durationInHours = 0;
while (tempDate.before(calEndDate))
{
if (taskCalendar.isDayWorking(tempDate.getTime()) && resourceCalendar.isDayWorking(tempDate.getTime()))
{
timeSpan = (long) taskCalendar.getWorkingHours(tempDate.getTime());
durationInHours = durationInHours + (timeSpan / OneHour);
}
tempDate.add(java.util.Calendar.DATE, 1);
}
tempDate.setTime(task.get(Tsk.START));
//Get Duration in Days
double durationInDays = 0;
while (tempDate.before(calEndDate))
{
if (taskCalendar.isDayWorking(tempDate.getTime()) && resourceCalendar.isDayWorking(tempDate.getTime()))
{
timeSpan = (long) taskCalendar.getWorkingHours(tempDate.getTime());
if ((timeSpan / OneHour) > 0)
durationInDays = durationInDays + (timeSpan/OneHour/8.0);
}
tempDate.add(java.util.Calendar.DATE, 1);
}
tempDate = calStartDate;
System.out.println("Duration in Minutes = " + durationInMins);
System.out.println("Duration in Hours = " + durationInHours);
System.out.println("Duration in Days = " + durationInDays);
System.out.println();
// The path to the documents directory.
String dataDir = Utils.getDataDir(MakeStandardCalendar.class);
//Create a project instance
Project project = new Project();
//Define Calendar and make it standard
Calendar cal1 = project.getCalendars().add("My Cal");
Calendar.makeStandardCalendar(cal1);
//Save the Project
project.save(dataDir + "Project.Xml", SaveFileFormat.XML);
//Display result of conversion.
System.out.println("Process completed Successfully");
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(MakeStandardCalendar.class);
// Create a project instance
Project project = new Project();
// Define Calendar and make it standard
Calendar cal1 = project.getCalendars().add("My Cal");
Calendar.makeStandardCalendar(cal1);
// Save the Project
project.save(dataDir + "Project.Xml", SaveFileFormat.XML);
private static void GetTestCalendar(Calendar cal)
{
Calendar.makeStandardCalendar(cal);
cal.setName("Test calendar");
CalendarException exc = new CalendarException();
Date curTime = java.util.Calendar.getInstance().getTime();
exc.setFromDate(curTime);
java.util.Calendar calObject = java.util.Calendar.getInstance();
calObject.add(java.util.Calendar.DATE, 2);
exc.setToDate(calObject.getTime());
exc.setDayWorking(true);
WorkingTime wt1 = new WorkingTime();
calObject.set(1,1,1, 9,0,0);
wt1.setFromTime(calObject.getTime());
calObject.set(1,1,1, 13,0,0);
wt1.setToTime(calObject.getTime());
WorkingTime wt2 = new WorkingTime();
calObject.set(1, 1, 1, 14, 0, 0);
wt2.setFromTime(calObject.getTime());
calObject.set(1, 1, 1, 19, 0, 0);
wt2.setToTime(calObject.getTime());
WorkingTime wt3 = new WorkingTime();
calObject.set(10, 1, 1, 20, 0, 0);
wt3.setFromTime(calObject.getTime());
calObject.set(10, 1, 1, 21, 0, 0);
wt3.setToTime(calObject.getTime());
exc.getWorkingTimes().add(wt1);
exc.getWorkingTimes().add(wt2);
exc.getWorkingTimes().add(wt3);
cal.getExceptions().add(exc);
CalendarException exc2 = new CalendarException();
java.util.Calendar newCal = java.util.Calendar.getInstance();
newCal.add(java.util.Calendar.DATE, 7);
exc2.setFromDate(newCal.getTime());
exc2.setToDate(exc2.getFromDate());
exc2.setDayWorking(false);
cal.getExceptions().add(exc2);
}
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
Calendar.makeStandardCalendar(cal);
cal.setName("Test calendar");
CalendarException exc = new CalendarException();
Date curTime = java.util.Calendar.getInstance().getTime();
exc.setFromDate(curTime);
java.util.Calendar calObject = java.util.Calendar.getInstance();
calObject.add(java.util.Calendar.DATE, 2);
exc.setToDate(calObject.getTime());
exc.setDayWorking(true);
WorkingTime wt1 = new WorkingTime();
calObject.set(1, 1, 1, 9, 0, 0);
wt1.setFromTime(calObject.getTime());
calObject.set(1, 1, 1, 13, 0, 0);
wt1.setToTime(calObject.getTime());
WorkingTime wt2 = new WorkingTime();
calObject.set(1, 1, 1, 14, 0, 0);
wt2.setFromTime(calObject.getTime());
calObject.set(1, 1, 1, 19, 0, 0);
wt2.setToTime(calObject.getTime());
WorkingTime wt3 = new WorkingTime();
calObject.set(10, 1, 1, 20, 0, 0);
wt3.setFromTime(calObject.getTime());
calObject.set(10, 1, 1, 21, 0, 0);
wt3.setToTime(calObject.getTime());
exc.getWorkingTimes().add(wt1);
exc.getWorkingTimes().add(wt2);
exc.getWorkingTimes().add(wt3);
cal.getExceptions().add(exc);
CalendarException exc2 = new CalendarException();
java.util.Calendar newCal = java.util.Calendar.getInstance();
newCal.add(java.util.Calendar.DATE, 7);
exc2.setFromDate(newCal.getTime());
exc2.setToDate(exc2.getFromDate());
exc2.setDayWorking(false);
cal.getExceptions().add(exc2);
// The path to the documents directory.
String dataDir = Utils.getDataDir(UpdatedCalendarToMpp.class);
String resultFile = "OutputMPP.mpp";
String newFile = "SampleMPP.mpp";
Project project = new Project(dataDir + newFile);
Calendar cal1 = project.getCalendars().add("Calendar 1");
GetTestCalendar(cal1);
project.set(Prj.CALENDAR, cal1);
//Save the Project
project.save(dataDir + resultFile, SaveFileFormat.MPP);
//Display result of conversion.
System.out.println("Process completed Successfully");
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(CurrencyCodes.class);
Project prj = new Project(dataDir + "project5.mpp");
System.out.println(prj.get(Prj.CURRENCY_CODE));
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(CurrencyCodes.class);
Project prj = new Project();
prj.set(Prj.CURRENCY_CODE, "USD");
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(CurrencyDigits.class);
Project project = new Project(dataDir + "project5.mpp");
System.out.println(project.get(Prj.CURRENCY_DIGITS));
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(CurrencyDigits.class);
Project project = new Project();
project.set(Prj.CURRENCY_DIGITS, 2);
project.save(dataDir + "ProjectCurrDigits.mpp", SaveFileFormat.MPP);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(CurrencySymbols.class);
Project project = new Project(dataDir + "project5.mpp");
System.out.println(project.get(Prj.CURRENCY_SYMBOL));
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(CurrencySymbols.class);
Project project = new Project();
project.set(Prj.CURRENCY_SYMBOL, "$$");
// The path to the documents directory.
String dataDir = Utils.getDataDir(WriteReadFormula.class);
Project proj = new Project(dataDir + "FormulaField.mpp"); // attached test mpp
ExtendedAttributeDefinition attr = proj.getExtendedAttributes().get(0);
System.out.println("Attribute Formula: " + attr.getFormula());
// The path to the documents directory.
String dataDir = Utils.getDataDir(WriteReadFormula.class);
Project project = new Project();
ExtendedAttributeDefinition attribute = ExtendedAttributeDefinition.createTaskDefinition(CustomFieldType.Cost,
ExtendedAttributeTask.Cost1, "");
attribute.setFormula("[Cost]-[Actual Cost]");
project.getExtendedAttributes().add(attribute);
// Add task
Task task = project.getRootTask().getChildren().add("Task");
// Create extended attribute
ExtendedAttribute extendedAttribute = attribute.createExtendedAttribute();
task.getExtendedAttributes().add(extendedAttribute);
// Display if extended attributes are read only or not
System.out.println(
extendedAttribute.getValueReadOnly() == true ? "Value is Read only" : "Value is not read only");
extendedAttribute.setTextValue("-36755");
System.out.println(
extendedAttribute.getTextValue() == " " ? "Formula values are read-only" : "Values are not read-only");
// The path to the documents directory.
String dataDir = Utils.getDataDir(WriteReadFormula.class);
Project project = new Project(dataDir + "New project 2010.mpp");
project.set(Prj.NEW_TASKS_ARE_MANUAL, new NullableBool(false));
// create new custom field (Task Text1) with formula which will double task cost
ExtendedAttributeDefinition attr = ExtendedAttributeDefinition.createTaskDefinition(CustomFieldType.Text,
ExtendedAttributeTask.Text1, "Custom");
attr.setAlias("Double Costs");
attr.setFormula("[Cost]*2");
project.getExtendedAttributes().add(attr);
// add a task to see the result in MSP
Task task = project.getRootTask().getChildren().add("Task");
// set task cost
task.set(Tsk.COST, BigDecimal.valueOf(100));
// see the result in the attached screenshot (result.jpg)
project.save(dataDir + "saved.mpp", SaveFileFormat.MPP);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(HandleExceptions.class);
Project project;
try {
project = new Project(dataDir + "ProjectWithException.mpp");
} catch (TasksReadingException ex) {
System.out.println("Message:");
System.out.println(ex.getMessage());
System.out.println("Log:");
System.out.println(ex.getLogText());
if (ex.getCause() != null) {
System.out.println("Inner exception message:");
System.out.println(ex.getCause().getMessage());
}
} catch (Exception e) {
System.out.println(e.getMessage());
}
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
String dataDir = Utils.getDataDir(ReportingServices.class);
// Project OverView
Project project3 = new Project(dataDir + "Cyclic stucture.mpp");
project3.saveReport(dataDir + "ProjectOverView.pdf", ReportType.ProjectOverview);
// Resource Cost Overview
Project project4 = new Project(dataDir + "OzBuild 16 Orig.mpp");
project4.saveReport(dataDir + "ResourceCostOverview.pdf", ReportType.ResourceCostOverview);
// Cost Overview
Project project5 = new Project(dataDir + "OzBuild 16 Orig.mpp");
project5.saveReport(dataDir + "CostOverview.pdf", ReportType.CostOverview);
// Work Overview
Project project6 = new Project(dataDir + "Residential Construction.mpp");
project6.saveReport(dataDir + "WorkOverview.pdf", ReportType.WorkOverview);
// Critical Tasks
Project project7 = new Project(dataDir + "Residential Construction.mpp");
project7.saveReport(dataDir + "CriticalTasks.pdf", ReportType.CriticalTasks);
// Milestones
Project project8 = new Project(dataDir + "Residential Construction.mpp");
project8.saveReport(dataDir + "Milestones.pdf", ReportType.Milestones);
// Late Tasks
Project project9 = new Project(dataDir + "Residential Construction.mpp");
project9.saveReport(dataDir + "LateTasks.pdf", ReportType.LateTasks);
// Resource Overview
Project project10 = new Project(dataDir + "Software Development Plan.mpp");
project10.saveReport(dataDir + "ResourceOverview.pdf", ReportType.ResourceOverview);
// Cost Overruns
Project project11 = new Project(dataDir + "Software Development.mpp");
project11.saveReport(dataDir + "CostOverruns.pdf", ReportType.CostOverruns);
// Upcoming Task
Project project12 = new Project(dataDir + "UpcomingTasks.mpp");
project12.saveReport(dataDir + "UpcomingTasks.pdf", ReportType.UpcomingTask);
// Task Cost Overview
Project project13 = new Project(dataDir + "Software Development.mpp");
project13.saveReport(dataDir + "TaskCostOverview.pdf", ReportType.TaskCostOverview);
// Over allocated Resources
Project project14 = new Project(dataDir + "Software Development Plan.mpp");
project14.saveReport(dataDir + "OverAllocatedResources.pdf", ReportType.OverallocatedResources);
// Slipping Tasks
Project project15 = new Project(dataDir + "Cyclic stucture.mpp");
project15.saveReport(dataDir + "SlippingTasks.pdf", ReportType.SlippingTasks);
// Best Practice Analyzer
Project project16 = new Project(dataDir + "Cyclic stucture.mpp");
project16.saveReport(dataDir + "BestPracticeAnalyzer.pdf", ReportType.BestPracticeAnalyzer);
// Burn down
Project project17 = new Project(dataDir + "Cyclic stucture.mpp");
project17.saveReport(dataDir + "Burndown.pdf", ReportType.Burndown);
// Cash Flow
Project project18 = new Project(dataDir + "OzBuild 16 Orig.mpp");
project18.saveReport(dataDir + "CashFlow.pdf", ReportType.CashFlow);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
RiskAnalyzer analyzer= new RiskAnalyzer(settings);
RiskAnalysisResult analysisResult = analyzer.analyze(project);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
Project project = new Project("NewProductDev.mpp"); // attached test project
// Initialize a risk pattern
Task task = project.getRootTask().getChildren().getById(14);
RiskPattern pattern = new RiskPattern(task);
// Select a distribution type for the random number generator to generate possible values from (only two types currently supported, namely normal and uniform)
// note that the normal distributions are often used in the natural and social sciences to represent real-valued random variables whose distributions are not known,
// thus this distribution is set to default (for more details see here: https://en.wikipedia.org/wiki/Normal_distribution)
pattern.setDistribution (ProbabilityDistributionType.Normal);
// Set the percentage of the most likely task duration which can happen in the best possible project scenario
// (the default value is 75, which means that if the estimated specified task duration is 4 days then the optimistic duration will be 3 days)
pattern.setOptimistic(70);
// Set the percentage of the most likely task duration which can happen in the worst possible project scenario
// (the defaut value is 125, which means that if the estimated specified task duration is 4 days then the pessimistic duration will be 5 days.).
pattern.setPessimistic(130);
// Set a confidence level that correspond to the percentage of the time the actual values will be within optimistic and pessimistic estimates.
// You can think of it as a value of standard deviation: the more uncertain about your estimates you are, the more the value of standard deviation used in random number generator is
pattern.setConfidenceLevel(ConfidenceLevel.CL75);
// you can add as many risk patterns as needed to model expected project risks
settings.getPatterns().add(pattern);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
RiskAnalysisSettings settings = new RiskAnalysisSettings();
// set a number of iterations for Monte Carlo simulation (the default value is 100).
settings.setIterationsCount(200);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
//Select the desired output (here we get early finish of the root task)
RiskItemStatistics rootEarlyFinish = analysisResult.getRiskItems(RiskItemType.EarlyFinish).get(project.getRootTask());
System.out.println("Expected value: "+ rootEarlyFinish.getExpectedValue());
System.out.println("StandardDeviation: " + rootEarlyFinish.getStandardDeviation());
System.out.println("10% Percentile: " +rootEarlyFinish.getPercentile(10));
System.out.println("50% Percentile: " + rootEarlyFinish.getPercentile(50));
System.out.println("90% Percentile: " + rootEarlyFinish.getPercentile(90));
System.out.println("Minimum: " + rootEarlyFinish.getMinimum());
System.out.println("Maximum: " + rootEarlyFinish.getMaximum());
// Also pdf report can be saved (it is rendered for Project Root Task Finish date):
analysisResult.saveReport("AnalysisReport.pdf");
// The path to the documents directory.
String dataDir = Utils.getDataDir(WriteMetadata.class);
long OneSec = 10000000;
long OneMin = 60 * OneSec;
long OneHour = 60 * OneMin;
long OneDayEightHour = 8 * OneHour;
long OneDayTwentyFourHour = 24 * OneHour;
Project project = new Project(dataDir + "New project 2010.mpp");
java.util.Calendar calendar = java.util.Calendar.getInstance(TimeZone.getTimeZone("GMT"));
calendar.set(2012, java.util.Calendar.DECEMBER, 7, 0, 0, 0);
Date startDate = calendar.getTime();
calendar.set(2013, java.util.Calendar.DECEMBER, 7, 0, 0, 0);
Date toDate = calendar.getTime();
WorkingTime wt = new WorkingTime();
wt.setFromTime(startDate);
wt.setToTime(toDate);
WeekDay day = project.get(Prj.CALENDAR).getWeekDays().toList().get(1);
day.getWorkingTimes().add(wt);
project.get(Prj.CALENDAR).setName("CHANGED NAME!");
Task task = project.getRootTask().getChildren().add("Task 1");
task.set(Tsk.DURATION_FORMAT, TimeUnitType.Day);
task.set(Tsk.DURATION, project.getDuration(3));
task.set(Tsk.CONTACT, "Rsc 1");
// new fields
task.set(Tsk.IS_MARKED, true);
task.set(Tsk.IGNORE_WARNINGS, true);
Task task2 = project.getRootTask().getChildren().add("Task 2");
task2.set(Tsk.DURATION_FORMAT, TimeUnitType.Day);
task2.set(Tsk.CONTACT, "Rsc 2");
project.getTaskLinks().add(task, task2, TaskLinkType.FinishToStart, project.getDuration(-1, TimeUnitType.Day));
calendar.set(2013, java.util.Calendar.DECEMBER, 13, 9, 0, 0);
startDate = calendar.getTime();
project.set(Prj.START_DATE, startDate);
Resource rsc = project.getResources().add("Rsc 1");
rsc.set(Rsc.TYPE, ResourceType.Work);
rsc.set(Rsc.INITIALS, "WR");
rsc.set(Rsc.ACCRUE_AT, CostAccrualType.Prorated);
rsc.set(Rsc.MAX_UNITS, 1d);
rsc.set(Rsc.CODE, "Code 1");
rsc.set(Rsc.GROUP, "Workers");
rsc.set(Rsc.E_MAIL_ADDRESS, "1@gmail.com");
rsc.set(Rsc.WINDOWS_USER_ACCOUNT, "user_acc1");
rsc.set(Rsc.IS_GENERIC, new NullableBool(true));
rsc.set(Rsc.ACCRUE_AT, CostAccrualType.End);
rsc.set(Rsc.STANDARD_RATE, BigDecimal.valueOf(10));
rsc.set(Rsc.STANDARD_RATE_FORMAT, RateFormatType.Day);
rsc.set(Rsc.OVERTIME_RATE, BigDecimal.valueOf(15));
rsc.set(Rsc.OVERTIME_RATE_FORMAT, RateFormatType.Hour);
rsc.set(Rsc.IS_TEAM_ASSIGNMENT_POOL, true);
rsc.set(Rsc.COST_CENTER, "Cost Center 1");
ResourceAssignment assn = project.getResourceAssignments().add(task, rsc);
assn.set(Asn.UID, 1);
assn.set(Asn.WORK, task.get(Tsk.DURATION));
assn.set(Asn.REMAINING_WORK, assn.get(Asn.WORK));
assn.set(Asn.REGULAR_WORK, assn.get(Asn.WORK));
task.set(Tsk.WORK, assn.get(Asn.WORK));
rsc.set(Rsc.WORK, task.get(Tsk.WORK));
assn.set(Asn.START, task.get(Tsk.START));
assn.set(Asn.FINISH, task.get(Tsk.FINISH));
// Add extended attribute for project and task
ExtendedAttributeDefinition attr = ExtendedAttributeDefinition.createTaskDefinition(CustomFieldType.Flag,
ExtendedAttributeTask.Flag1, "My Flag Field");
project.getExtendedAttributes().add(attr);
ExtendedAttribute taskAttr = attr.createExtendedAttribute();
taskAttr.setFlagValue(true);
task2.getExtendedAttributes().add(taskAttr);
project.save(dataDir + "updated.mpp", SaveFileFormat.MPP);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(WriteMetadata.class);
long OneSec = 10000000;
long OneMin = 60 * OneSec;
long OneHour = 60 * OneMin;
long OneDayEightHour = 8 * OneHour;
long OneDayTwentyFourHour = 24 * OneHour;
Project project = new Project(dataDir + "New project 2010.mpp");
java.util.Calendar calendar = java.util.Calendar.getInstance(TimeZone.getTimeZone("GMT"));
calendar.set(2012, java.util.Calendar.DECEMBER, 7, 0, 0, 0);
Date startDate = calendar.getTime();
calendar.set(2013, java.util.Calendar.DECEMBER, 7, 0, 0, 0);
Date toDate = calendar.getTime();
WorkingTime wt = new WorkingTime();
wt.setFromTime(startDate);
wt.setToTime(toDate);
WeekDay day = project.get(Prj.CALENDAR).getWeekDays().toList().get(1);
day.getWorkingTimes().add(wt);
project.get(Prj.CALENDAR).setName("CHANGED NAME!");
Task task = project.getRootTask().getChildren().add("Task 1");
task.set(Tsk.DURATION_FORMAT, TimeUnitType.Day);
task.set(Tsk.DURATION, project.getDuration(3));
task.set(Tsk.CONTACT, "Rsc 1");
// new fields
task.set(Tsk.IS_MARKED, true);
task.set(Tsk.IGNORE_WARNINGS, true);
Task task2 = project.getRootTask().getChildren().add("Task 2");
task2.set(Tsk.DURATION_FORMAT, TimeUnitType.Day);
task2.set(Tsk.CONTACT, "Rsc 2");
project.getTaskLinks().add(task, task2, TaskLinkType.FinishToStart, project.getDuration(-1, TimeUnitType.Day));
calendar.set(2013, java.util.Calendar.DECEMBER, 13, 9, 0, 0);
startDate = calendar.getTime();
project.set(Prj.START_DATE, startDate);
Resource rsc = project.getResources().add("Rsc 1");
rsc.set(Rsc.TYPE, ResourceType.Work);
rsc.set(Rsc.INITIALS, "WR");
rsc.set(Rsc.ACCRUE_AT, CostAccrualType.Prorated);
rsc.set(Rsc.MAX_UNITS, 1d);
rsc.set(Rsc.CODE, "Code 1");
rsc.set(Rsc.GROUP, "Workers");
rsc.set(Rsc.E_MAIL_ADDRESS, "1@gmail.com");
rsc.set(Rsc.WINDOWS_USER_ACCOUNT, "user_acc1");
rsc.set(Rsc.IS_GENERIC, new NullableBool(true));
rsc.set(Rsc.ACCRUE_AT, CostAccrualType.End);
rsc.set(Rsc.STANDARD_RATE, BigDecimal.valueOf(10));
rsc.set(Rsc.STANDARD_RATE_FORMAT, RateFormatType.Day);
rsc.set(Rsc.OVERTIME_RATE, BigDecimal.valueOf(15));
rsc.set(Rsc.OVERTIME_RATE_FORMAT, RateFormatType.Hour);
rsc.set(Rsc.IS_TEAM_ASSIGNMENT_POOL, true);
rsc.set(Rsc.COST_CENTER, "Cost Center 1");
ResourceAssignment assn = project.getResourceAssignments().add(task, rsc);
assn.set(Asn.UID, 1);
assn.set(Asn.WORK, task.get(Tsk.DURATION));
assn.set(Asn.REMAINING_WORK, assn.get(Asn.WORK));
assn.set(Asn.REGULAR_WORK, assn.get(Asn.WORK));
task.set(Tsk.WORK, assn.get(Asn.WORK));
rsc.set(Rsc.WORK, task.get(Tsk.WORK));
assn.set(Asn.START, task.get(Tsk.START));
assn.set(Asn.FINISH, task.get(Tsk.FINISH));
ExtendedAttributeDefinition attr = new ExtendedAttributeDefinition();
attr.setFieldId(String.valueOf((int) ExtendedAttributeTask.Flag1));
attr.setAlias("Labeled");
project.getExtendedAttributes().add(attr);
ExtendedAttribute taskAttr = new ExtendedAttribute();
taskAttr.setValue("1");
taskAttr.setFieldId(attr.getFieldId());
task2.getExtendedAttributes().add(taskAttr);
project.save(dataDir + "updated.mpp", SaveFileFormat.MPP);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(WriteUpdatedOutlineCode.class);
String newFile = "New Project 2013.mpp";
String resultFile = "OutputMPP.mpp";
Project project = new Project(dataDir + newFile);
ArrayList projectOutlCodes = new ArrayList();
OutlineCodeDefinition code1 = new OutlineCodeDefinition();
code1.setAlias("New task outline code1");
code1.setFieldId(String.valueOf((int) ExtendedAttributeTask.OutlineCode1));
code1.setFieldName("Outline Code1");
OutlineMask mask = new OutlineMask();
mask.setSeparator("+");
mask.setLevel(1);
mask.setType(MaskType.Numbers);
code1.getMasks().add(mask);
OutlineValue value = new OutlineValue();
value.setDescription("Value description");
value.setValueId(1);
value.setValue("123456");
value.setType(OutlineValueType.Number);
code1.getValues().add(value);
project.getOutlineCodes().add(code1);
OutlineCodeDefinition code2 = new OutlineCodeDefinition();
code2.setAlias("New rsc outline code2");
code2.setFieldId(String.valueOf((int) ExtendedAttributeResource.OutlineCode2));
code2.setFieldName("Outline Code2");
OutlineMask mask2 = new OutlineMask();
mask2.setSeparator("/");
mask2.setLevel(1);
mask2.setType(MaskType.Numbers);
code2.getMasks().add(mask2);
OutlineValue value2 = new OutlineValue();
value2.setDescription("Value2 description");
value2.setValueId(2);
value2.setValue("987654");
value2.setType(OutlineValueType.Number);
// Save the Project
project.save(dataDir + "Project.Mpp", SaveFileFormat.MPP);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(ConfigureGanttChartView.class);
Project project = new Project(dataDir + "New project 2010.mpp");
// Create a new project task
Task task = project.getRootTask().getChildren().add("New Activity");
// Add custom text attribute to created task.
ExtendedAttribute attr = new ExtendedAttribute();
attr.setFieldId(String.valueOf((int) ExtendedAttributeTask.Text1));
attr.setValue("Activity attribute");
task.getExtendedAttributes().add(attr);
// Customize table by adding text attribute field
TableField attrField = new TableField();
attrField.setField(Field.TaskText1);
attrField.setWidth(20);
attrField.setTitle("Custom attribute");
attrField.setAlignTitle(StringAlignment.Center);
attrField.setAlignData(StringAlignment.Center);
Table table = project.getTables().toList().get(0);
table.getTableFields().add(3, attrField);
// The result of opening of saved project in MSP2010 is in attached
// screenshot
project.save("saved.mpp", SaveFileFormat.MPP);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(CreateEmptyProjectFile.class);
//Create a project instance
Project newProject = new Project();
newProject.save(dataDir + "Project1.xml", SaveFileFormat.XML);
//Display result of conversion.
System.out.println("Project file generated Successfully");
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(CriticalPath.class);
Project project = new Project(dataDir + "New project 2010.mpp");
project.setCalculationMode(CalculationMode.Automatic);
Task subtask1 = project.getRootTask().getChildren().add("1");
Task subtask2 = project.getRootTask().getChildren().add("2");
Task subtask3 = project.getRootTask().getChildren().add("3");
project.getTaskLinks().add(subtask1, subtask2, TaskLinkType.FinishToStart);
// Display the critical path now
for (Task task : project.getCriticalPath()) {
System.out.println(task.get(Tsk.NAME));
}
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(ReadCurrencyProperties.class);
// Create a project reader instance
Project project = new Project(dataDir + "project.mpp");
// Display currency properties
System.out.println("Currency Code : " + project.get(Prj.CURRENCY_CODE).toString());
System.out.println("<br>Currency Digits : " + project.get(Prj.CURRENCY_DIGITS).toString());
System.out.println("<br>Currency Symbol : " + project.get(Prj.CURRENCY_SYMBOL).toString());
System.out.println("Currency Symbol Position" + project.get(Prj.CURRENCY_SYMBOL_POSITION).toString());
// Display result of conversion.
System.out.println("Process completed Successfully");
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(SetCurrencyProperties.class);
// Create a project instance
Project project = new Project();
// Set currency properties
project.set(Prj.CURRENCY_CODE, "AUD");
project.set(Prj.CURRENCY_DIGITS, 2);
project.set(Prj.CURRENCY_SYMBOL, "$");
project.set(Prj.CURRENCY_SYMBOL_POSITION, CurrencySymbolPositionType.After);
// Save the project as XML project file
project.save(dataDir + "project.xml", SaveFileFormat.XML);
// Display result of conversion.
System.out.println("Process completed Successfully");
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(DefaultProjectProperties.class);
Project project = new Project(dataDir + "New Project 2007.mpp");
project.getTaskLinks().add(project.getRootTask().getChildren()
.add("Task 1"), project.getRootTask().getChildren()
.add("Task 2"));
GanttChartView view = (GanttChartView)project.getDefaultView();
view.getMiddleTimescaleTier().setUnit(TimescaleUnit.Months);
project.set(Prj.TIMESCALE_START, new Date(112, 7, 6));
view.getMiddleTimescaleTier().setDateTimeConverter( new DateTimeConverter() {
public String invoke(java.util.Date date)
{
Calendar cal = Calendar.getInstance();
cal.setTime(date);
int month = cal.get(Calendar.MONTH);
return new String[] { "Jan.", "Feb.", "Mar.", "Apr.","May.", "Jun.", "July.","Aug.", "Sep.", "Oct.", "Nov.", "Dec." }[month];
}
});
project.save("saved.pdf", SaveFileFormat.PDF);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(DefaultProjectProperties.class);
Project project = new Project(dataDir + "project.mpp");
// Display default properties
System.out.println("Project Version : " + project.get(Prj.SAVE_VERSION));
System.out.println("New Task Default Start: " + project.get(Prj.DEFAULT_START_TIME));
System.out.println("New Task Default Type: " + project.get(Prj.DEFAULT_TASK_TYPE));
System.out.println("Resource Default Standard Rate: " + project.get(Prj.DEFAULT_STANDARD_RATE));
System.out.println("Resource Default Overtime Rate: " + project.get(Prj.DEFAULT_OVERTIME_RATE));
System.out.println("Default Task EV Method: " + project.get(Prj.DEFAULT_TASK_EV_METHOD));
System.out.println("Default Cost Accrual: " + project.get(Prj.DEFAULT_FIXED_COST_ACCRUAL));
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
// Set default properties
project.set(Prj.SCHEDULE_FROM_START, new NullableBool(true));
java.util.Calendar cal = java.util.Calendar.getInstance();
cal.set(2014, 2, 15, 0, 0, 0);
project.set(Prj.START_DATE, cal.getTime());
project.set(Prj.DEFAULT_START_TIME, project.get(Prj.START_DATE));
project.set(Prj.DEFAULT_TASK_TYPE, TaskType.FixedDuration);
project.set(Prj.DEFAULT_STANDARD_RATE, 15d);
project.set(Prj.DEFAULT_OVERTIME_RATE, 12d);
project.set(Prj.DEFAULT_TASK_EV_METHOD, EarnedValueMethodType.PercentComplete);
project.set(Prj.DEFAULT_FIXED_COST_ACCRUAL, CostAccrualType.Prorated);
// Save the project to XML format
project.save(dataDir + "Project4.xml", SaveFileFormat.XML);
// Display result of conversion.
System.out.println("Process completed Successfully");
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(DetermineProjectVersion.class);
Project project = new Project(dataDir + "input.xml");
// Display project version property
System.out.println("Project Version : " + project.get(Prj.SAVE_VERSION));
System.out.println("Last Saved : " + project.get(Prj.LAST_SAVED));
// Display result of conversion.
System.out.println("Process completed Successfully");
// The path to the documents directory.
String dataDir = Utils.getDataDir(ExtendedAttributes.class);
Project prj = new Project(dataDir + "project5.mpp");
ExtendedAttributeDefinitionCollection eads = prj.getExtendedAttributes();
// Create extended attribute definition
ExtendedAttributeDefinition attributeDefinition = ExtendedAttributeDefinition
.createTaskDefinition(CustomFieldType.Start, ExtendedAttributeTask.Start7, "Start 7");
prj.getExtendedAttributes().add(attributeDefinition);
eads.add(attributeDefinition);
// Get zero index task
Task tsk = prj.getRootTask().getChildren().getById(1);
ExtendedAttributeCollection eas = tsk.getExtendedAttributes();
// Add extended attribute
ExtendedAttribute ea = attributeDefinition.createExtendedAttribute();
ea.setFieldId(attributeDefinition.getFieldId());
Date date = new Date();
ea.setDateValue(date);
eas.add(ea);
prj.save(dataDir + "Project5.xml", SaveFileFormat.XML);
// Display result of conversion.
System.out.println("Process completed Successfully");
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(ExtendedAttributes.class);
Project prj = new Project(dataDir + "project5.mpp");
ExtendedAttributeDefinitionCollection eads = prj.getExtendedAttributes();
// Create extended attribute definition
ExtendedAttributeDefinition ead = new ExtendedAttributeDefinition();
ead.setFieldId(Integer.toString(ExtendedAttributeTask.Start7));
ead.setFieldName("Start7");
eads.add(ead);
// Get zero index task
Task tsk = prj.getRootTask().getChildren().getById(1);
ExtendedAttributeCollection eas = tsk.getExtendedAttributes();
String dateTimeFormat = "yyyy-MM-ddTHH:mm:ss";
ExtendedAttribute ea = new ExtendedAttribute();
ea.setFieldId(ead.getFieldId());
ea.setValue("2013-12-05 09:00:00");
eas.add(ea);
prj.save(dataDir + "Project5.xml", SaveFileFormat.XML);
// Display result of conversion.
System.out.println("Process completed Successfully");
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(ExtractingEmbeddedObjects.class);
Project project = new Project(dataDir + "EmbeddedFile.mpp");
OleObject ole = project.getOleObjects().toList().get(0);
// we have to check this property because it can be null if the embedded
// object was created inside the ms project application
// Or, alternatively, you can use this check: if (ole.FileFormat ==
// "Package")
// if (!string.IsNullOrEmpty(ole.FullPath))
if (ole.getFileFormat().equals("Package")) {
File file = new File(dataDir);
FileOutputStream fop = new FileOutputStream(file);
// get the content in bytes
byte[] contentInBytes = ole.getContent();
fop.write(contentInBytes);
fop.flush();
fop.close();
}
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(FilterDataFromMppFile.class);
Project project = new Project(dataDir + "Task name filter.mpp");
Filter filter = project.getTaskFilters().toList().get(1);
System.out.println(filter.getCriteria().getCriteriaRows().size());
System.out.println(filter.getCriteria().getOperation());
FilterCriteria criteria1 = filter.getCriteria().getCriteriaRows().get(0);
System.out.println(criteria1.getTest());
System.out.println(criteria1.getField());
// System.out.println(criteria1.getValues().getValues().get(0).toString());
FilterCriteria criteria2 = filter.getCriteria().getCriteriaRows().get(1);
System.out.println(criteria2.getOperation());
System.out.println(criteria2.getCriteriaRows().size());
FilterCriteria criteria21 = criteria2.getCriteriaRows().get(0);
System.out.println(criteria21.getTest());
System.out.println(criteria21.getField());
FilterCriteria criteria22 = criteria2.getCriteriaRows().get(1);
System.out.println(criteria22.getTest());
System.out.println(criteria22.getField());
FilterCriteria criteria23 = criteria2.getCriteriaRows().get(2);
System.out.println(criteria23.getTest());
System.out.println(criteria23.getField());
FilterCriteria criteria3 = filter.getCriteria().getCriteriaRows().get(2);
System.out.println(criteria3.getCriteriaRows().size());
System.out.println(criteria3.getOperation());
System.out.println(filter.getCriteria());
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(FilterDataFromMppFile.class);
Project project = new Project(dataDir + "Project2003.mpp");
List<Filter> taskFilters = project.getTaskFilters().toList();
System.out.println("Task Filters Count: " + taskFilters.size());
System.out.println("All Tasks: " + taskFilters.get(0).getName());
System.out.println("Task Item: " + taskFilters.get(0).getFilterType());
System.out.println("Task Filters Show In Menu: " + taskFilters.get(0).getShowInMenu());
System.out.println("Task filter ShowRelatedSummaryRows: " + taskFilters.get(0).getShowRelatedSummaryRows());
System.out.println("Task filter type: " + taskFilters.get(1).getFilterType());
System.out.println("Task Filters Show In Menu: " + taskFilters.get(1).getShowInMenu());
System.out.println("Task filter ShowRelatedSummaryRows: " + taskFilters.get(1).getShowRelatedSummaryRows());
System.out.println("NEW FILTER" + taskFilters.get(2).getName());
System.out.println("Task filter type: " + taskFilters.get(2).getShowInMenu());
System.out.println("Task Filters Show In Menu: " + taskFilters.get(2).getShowInMenu());
System.out.println("Task filter ShowRelatedSummaryRows: " + taskFilters.get(2).getShowRelatedSummaryRows());
System.out.println("Task FilterCriteria:m" + taskFilters.get(2).getCriteria());
System.out.println("(TaskName Contains T)" + taskFilters.get(2).getCriteria().toString());
List<Filter> rscFilters = project.getResourceFilters().toList();
System.out.println("Project.ResourceFilters count: " + rscFilters.size());
System.out.println("Resource Filter Item Type: Item.ResourceType: " + rscFilters.get(0).getFilterType());
System.out.println("Resource filter ShowInMenu" + rscFilters.get(0).getShowInMenu());
System.out.println("Resource filter ShowRelatedSummaryRows: " + rscFilters.get(0).getShowRelatedSummaryRows());
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(FiscalYearProperties.class);
;
Project project = new Project(dataDir + "project.mpp");
// Display fiscal year properties
// Display fiscal year properties
System.out.println("Fiscal Year Start Date : " + project.get(Prj.FY_START_DATE));
System.out.println("Fiscal Year Numbering : " + project.get(Prj.FISCAL_YEAR_START));
// ------ Setting Project Fiscal Year Properties
// Create a project instance
Project prj = new Project();
// Set fiscal year properties
prj.set(Prj.FY_START_DATE, Month.July);
prj.set(Prj.FISCAL_YEAR_START, new NullableBool(true));
// Save the project as XML project file
prj.save(dataDir + "savedProject.xml", SaveFileFormat.XML);
// Display result of conversion.
System.out.println("Process completed Successfully");
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(ReadProjectInfo.class);
Project project = new Project(dataDir + "input.xml");
if (project.get(Prj.SCHEDULE_FROM_START).getValue())
System.out.println("Project Start Date : " + project.get(Prj.START_DATE));
else
System.out.println("Project Finish Date : " + project.get(Prj.FINISH_DATE));
String strSchdl = (project.get(Prj.SCHEDULE_FROM_START).getValue()) ? "Project Start Date"
: "Project Finish Date";
System.out.println("Project Schedule From : " + strSchdl);
System.out.println("Current Date : " + project.get(Prj.CURRENT_DATE));
System.out.println("Status Date : " + project.get(Prj.STATUS_DATE));
System.out.println("Calendar : " + project.get(Prj.CALENDAR).getName());
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(WriteProjectInfo.class);
// Create a project instance
Project project = new Project();
// Set project information properties
project.set(Prj.SCHEDULE_FROM_START, new NullableBool(true));
java.util.Calendar cal = java.util.Calendar.getInstance();
cal.set(2014, 7, 10);
project.set(Prj.START_DATE, cal.getTime());
project.set(Prj.CURRENT_DATE, cal.getTime());
project.set(Prj.STATUS_DATE, cal.getTime());
// Save the Project as XML
project.save(dataDir + "project3.xml", SaveFileFormat.XML);
Project project = new Project(projectName);
Date dtStartDate, dtEndDate;
java.util.Calendar cal = java.util.Calendar.getInstance();
cal.setTime(project.get(Prj.START_DATE));
cal.add(java.util.Calendar.DAY_OF_MONTH, 7); //add 7 days from start of project
dtStartDate = cal.getTime();
//Get Finish date with 30 days offset
cal.setTime(project.get(Prj.FINISH_DATE));
cal.add(java.util.Calendar.DAY_OF_MONTH, -30);
dtEndDate = cal.getTime();
ImageSaveOptions options = new ImageSaveOptions(SaveFileFormat.PNG);
{
options.setSaveToSeparateFiles(true);
options.setPageSize(PageSize.A3);
options.setTimescale(Timescale.Months);
options.setStartDate (dtStartDate);
options.setEndDate(dtEndDate);
};
int pageCount = project.getPageCount_PageSize(
PageSize.A3,
Timescale.Months,
dtStartDate,
dtEndDate);
System.out.println("Number of Pages = " + pageCount);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
// Read the source Project
Project project = new Project(projectName);
// Get number of pages
System.out
.println("Number of Pages = " + project.getPageCount(PresentationFormat.ResourceUsage, Timescale.Days));
// Get number of pages (Months)
System.out.println(
"Number of Pages = " + project.getPageCount(PresentationFormat.ResourceUsage, Timescale.Months));
// Get number of pages (ThirdsOfMonths)
System.out.println("Number of Pages = "
+ project.getPageCount(PresentationFormat.ResourceUsage, Timescale.ThirdsOfMonths));
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
Project project = new Project(projectName);
// Get number of pages
int iPages = project.getPageCount();
// Get number of pages (Timescale.Months)
iPages = project.getPageCount(0, Timescale.Months);
// Get number of pages (Timescale.ThirdsOfMonths)
iPages = project.getPageCount(0, Timescale.ThirdsOfMonths);
public static void main(String[] args) throws IOException {
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(ReadingProjectDatafromMicrosoftProjectDatabase.class);
InputStream stream = null;
try
{
stream = new ByteArrayInputStream(getModifiedXml().getBytes("utf-8"));
}
catch (UnsupportedEncodingException e)
{
e.printStackTrace();
}
Project project = new Project(stream, new ParseErrorCallback()
{
public Object invoke(Object sender, ParseErrorArgs args)
{
return customDurationHandler(sender, args);
}
});
project.save(dataDir + "Project1.xml", SaveFileFormat.XML);
}
private static String getModifiedXml()
{
StringBuilder xml = new StringBuilder();
BufferedReader reader;
String line;
try
{
reader = new BufferedReader(new InputStreamReader(new FileInputStream("NewProductDev.xml"), "UTF8"));
while ((line = reader.readLine()) != null)
{
xml.append(line).append("\n");
}
}
catch (Exception e)
{
e.printStackTrace();
}
return xml.toString().replaceAll("PT(\\d+)H(\\d+)M(\\d+)S", "**$1Hrs$2Mins$3Secs**");
}
private static Object customDurationHandler(Object sender, ParseErrorArgs args)
{
System.err.print(String.format("Object field : %s; Invalid value : %s; ", args.getFieldName(), args.getInvalidValue()));
String duration = args.getInvalidValue().replaceAll("[*]{2}(\\d+)Hrs(\\d+)Mins(\\d+)Secs[*]{2}", "PT$1H$2M$3S");
double newValue = Duration.parseTimeSpan(duration)*0.001/60/60;
System.err.println(String.format("New value : %s", duration));
Project project = new Project();
return project.getDuration(newValue, TimeUnitType.Hour);
}
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(ImportExportDataToPrimavera.class);
Project project = new Project(dataDir + "Project.mpp");
project.save(dataDir + "saved.mpx", SaveFileFormat.MPX);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(ImportExportDataToPrimavera.class);
Project project = new Project(dataDir + "Project.mpp");
project.save(dataDir + "saved.xer", SaveFileFormat.PrimaveraXER);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(ImportExportDataToPrimavera.class);
Project project = new Project(dataDir + "Project.mpp");
project.save(dataDir + "saved.xml", SaveFileFormat.PrimaveraP6XML);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(ImportExportDataToPrimavera.class);
Project project = new Project(dataDir +"Primavera1.mpx");
// read the project structure
ProjectFileInfo info = Project.getProjectFileInfo("primavera1.mpx");
System.out.println(info.getProjectFileFormat());
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(ImportExportDataToPrimavera.class);
Project project = new Project(dataDir + "Primavera1.xml");
// read the project structure
ProjectFileInfo info = Project.getProjectFileInfo("primavera1.xml");
System.out.println(info.getProjectFileFormat());
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
Project project = new Project("test.xml");
PrimaveraXmlSaveOptions options = new PrimaveraXmlSaveOptions();
options.setSaveRootTask(false);
project.save("test1.xml",options);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
PrimaveraXmlReader reader = new PrimaveraXmlReader("primaveraXml.xml");
List<Integer> listOpProjectUids = reader.getProjectUids();
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
PrimaveraXmlReadingOptions options = new PrimaveraXmlReadingOptions();
options.setProjectUid(4557);
// returns project with special Uid
Project project = new Project("PrimaveraXmlFile.xml",options);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(MppFileUpdate.class);
long OneSec = 10000000;// microsecond * 10
long OneMin = 60 * OneSec;
long OneHour = 60 * OneMin;
// Read an existing project
Project project = new Project(dataDir + "SampleMSP2010.mpp");
// create a new task
Task task = project.getRootTask().getChildren().add("Task1");
// set start date
java.util.Calendar cal = java.util.Calendar.getInstance();
cal.set(2012, 7, 1, 8, 0, 0);
task.set(Tsk.START, cal.getTime());
cal.set(2012, 7, 1, 17, 0, 0);
task.set(Tsk.FINISH, cal.getTime());
// Save the project as MPP project file
project.save(dataDir + "AfterLinking.Mpp", SaveFileFormat.MPP);
// Display result of conversion.
System.out.println("Process completed Successfully");
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(PrintPagesToSeparateImage.class);
Project project = new Project(dataDir + "CustomerFeedback.mpp");
ImageSaveOptions saveOptions = new ImageSaveOptions(SaveFileFormat.PNG);
java.util.Calendar cal = java.util.Calendar.getInstance();
cal.setTime(project.get(Prj.START_DATE));
cal.add(java.util.Calendar.DATE, -3);
saveOptions.setStartDate(cal.getTime());
saveOptions.setEndDate(project.get(Prj.FINISH_DATE));
saveOptions.setMarkCriticalTasks(true);
saveOptions.setLegendOnEachPage(false);
saveOptions.setGridlines(new ArrayList<Gridline>());
Gridline gridline = new Gridline();
gridline.setGridlineType(GridlineType.GanttRow);
gridline.setColor(Color.BLUE);
gridline.setPattern(LinePattern.Dashed);
saveOptions.getGridlines().add(gridline);
// Save the whole project layout to one file
project.save(dataDir + "CustomerFeedback.png", saveOptions);
// Save project layout to separate files
saveOptions.setSaveToSeparateFiles(true);
project.save(dataDir + "CustomerFeedback_.png", saveOptions);
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(PrintTaskWritingExceptions.class);
Project prj = new Project(dataDir + "Project5.mpp");
try {
prj.save(dataDir + "project.MPP", SaveFileFormat.MPP);
} catch (TasksWritingException ex) {
System.out.println(ex.getLogText());
}
// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
String testDir = Utils.getDataDir(ReadGroupDefinitionData.class);
Project project = new Project(testDir + "Task name filter.mpp");
System.out.println("Task Groups Count: " + project.getTaskGroups().size());
Group taskGroup = project.getTaskGroups().toList().get(1);
System.out.println("Percent Complete:" + taskGroup.getName());
System.out.println("Group Criteria count: " + taskGroup.getGroupCriteria().size());
System.out.println("\n************* Retrieving Task Group's Criterion information *************");
GroupCriterion criterion = taskGroup.getGroupCriteria().toList().get(0);
System.out.println("Criterion Field: " + criterion.getField());