Working with Project Properties

Working with General Project Properties

Microsoft Project saves project properties, metadata, for every project. The properties include the project’s start and end dates, the current date and the status date, the type of calendar used and when a project is scheduled from. Aspose.Tasks for Java lets you read and set project properties. This topic shows how.

Please note that you cannot set values against the Application and Producer fields, because Aspose Ltd. and Aspose.Tasks for Java x.x.x will be displayed against these fields

Reading Project Information

The Prj class has a number of properties that deal with project properties:

To read project properties in Microsoft Project, click Project Information on the Project menu.

Reading project properties in Microsoft Project

working with Microsoft Project properties

The programming samples below show how to read and output the project start and end date, whether the project is scheduled from the start or end, the current date, status date, and the calendar type.

Writing Project Information

Aspose.Tasks for Java can write as well as read project information. The code samples below show how to set the scheduling start point, the start date, current date, status date, and calendar type.

Determining Project Version

Aspose.Tasks for Java lets you retrieve project file information such as the version of Microsoft Project that the file was created with. The Project class exposes the get() method for getting this information using the static Project class.

The SAVE_VERSION and LAST_SAVED properties exposed by the Project class is used to determine the project version and the date when the project was last saved.

 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(DetermineProjectVersion.class);
 4Project project = new Project(dataDir + "input.xml");
 5// Display project version property
 6System.out.println("Project Version : " + project.get(Prj.SAVE_VERSION));
 7System.out.println("Last Saved : " + project.get(Prj.LAST_SAVED));
 8
 9// Display result of conversion.
10System.out.println("Process completed Successfully");

Default Project Properties

Microsoft Project lets users set default project properties that speed up the process of setting up a project. The default properties define when a new task starts and finishes, sets the default overtime and standard pay rates and more. Aspose.Tasks for Java supports these features. This article explains both how to read default properties and how to write default properties to a project file.

The Prj class exposes a number of properties for managing a project’s default properties:

To see the default project information in Microsoft Project:

  1. Open a project.
  2. On the Tools menu, click Options.
  3. Go to the General tab. Here, you can see the settings for the default standard and overtime rates.
  4. Go to the Schedule tab. Here, you can see the settings for the default task type and default task start time.

Default project information in Microsoft Project, as written by Aspose.Tasks

viewing project properties in Microsoft Project

Reading Default Properties

The following example reads a project’s default properties and writes them to a console window.

 1// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
 2
 3        // The path to the documents directory.
 4        String dataDir = Utils.getDataDir(DefaultProjectProperties.class);
 5
 6        Project project = new Project(dataDir + "project.mpp");
 7
 8        // Display default properties
 9        System.out.println("Project Version : " + project.get(Prj.SAVE_VERSION));
10        System.out.println("New Task Default Start: " + project.get(Prj.DEFAULT_START_TIME));
11        System.out.println("New Task Default Type: " + project.get(Prj.DEFAULT_TASK_TYPE));
12        System.out.println("Resource Default Standard Rate: " + project.get(Prj.DEFAULT_STANDARD_RATE));
13        System.out.println("Resource Default Overtime Rate: " + project.get(Prj.DEFAULT_OVERTIME_RATE));
14        System.out.println("Default Task EV Method: " + project.get(Prj.DEFAULT_TASK_EV_METHOD));
15        System.out.println("Default Cost Accrual: " + project.get(Prj.DEFAULT_FIXED_COST_ACCRUAL));

Writing Default Properties

The following lines of code set a project’s default properties.

 1// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
 2// Set default properties
 3project.set(Prj.SCHEDULE_FROM_START, new NullableBool(true));
 4
 5java.util.Calendar cal = java.util.Calendar.getInstance();
 6cal.set(2014, 2, 15, 0, 0, 0);
 7
 8project.set(Prj.START_DATE, cal.getTime());
 9project.set(Prj.DEFAULT_START_TIME, project.get(Prj.START_DATE));
10project.set(Prj.DEFAULT_TASK_TYPE, TaskType.FixedDuration);
11project.set(Prj.DEFAULT_STANDARD_RATE, 15d);
12project.set(Prj.DEFAULT_OVERTIME_RATE, 12d);
13project.set(Prj.DEFAULT_TASK_EV_METHOD, EarnedValueMethodType.PercentComplete);
14project.set(Prj.DEFAULT_FIXED_COST_ACCRUAL, CostAccrualType.Prorated);
15
16// Save the project to XML format
17project.save(dataDir + "Project4.xml", SaveFileFormat.XML);
18
19// Display result of conversion.
20System.out.println("Process completed Successfully");

Writing Project Summary Information

Most programs save summary information with the files they save. Microsoft Project is no different. As well as the name of the author, the date the project was created and the last time it was edited and saved, it saves keywords, subject, comments and more. Aspose.Tasks for Java lets you both read and write this type of information. This topic explains how to open a project file, set the summary information and save it again.

The Prj class exposes a number of properties to set or get summary information about an MPP project file. Aspose.Tasks for Java can update the project summary information and then write the project file back to MPP. To update the project summary information of an existing MPP file:

  1. Create an instance of the Project class to read the input MPP file
  2. Set the various properties exposed by the Project object to define summary information.
  3. Save the Project using the Save method of Project class

To see the a file’s summary information:

  1. Find the file in a file browser.
  2. Right-click the file and select Properties.
  3. Go to the Details tab.
 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(WriteMPPProjectSummary.class);
 4
 5Project project = new Project(dataDir + "project.mpp");
 6
 7// Set some summary information about the project
 8project.set(Prj.AUTHOR, "Author");
 9project.set(Prj.LAST_AUTHOR, "Last Author");
10project.set(Prj.REVISION, 15);
11project.set(Prj.KEYWORDS, "MSP Aspose");
12project.set(Prj.COMMENTS, "Comments");
13
14java.util.Calendar cal = java.util.Calendar.getInstance();
15cal.set(2014, 2, 15, 0, 0, 0);
16project.set(Prj.CREATION_DATE, cal.getTime());
17project.set(Prj.KEYWORDS, "MPP Aspose");
18cal.set(2014, 3, 16, 0, 0, 0);
19project.set(Prj.LAST_PRINTED, cal.getTime());
20
21project.save(dataDir + "MPPAspose.xml", SaveFileFormat.XML);
22
23// Display result of conversion.
24System.out.println("Process completed Successfully");
25
26// Reading Project Summary Information
27project = new Project(dataDir + "MPPAspose.xml");
28
29System.out.println("Author: " + project.get(Prj.AUTHOR));
30System.out.println(project.get(Prj.LAST_AUTHOR));
31System.out.println(project.get(Prj.REVISION));
32System.out.println(project.get(Prj.KEYWORDS));
33System.out.println(project.get(Prj.COMMENTS));
34
35System.out.println(project.get(Prj.CREATION_DATE).toString());
36System.out.println(project.get(Prj.KEYWORDS));
37System.out.println(project.get(Prj.LAST_PRINTED).toString());

Fiscal Year Properties

The fiscal year is the same as a financial year or budget year. It is the dates between which a country, an organization or an individual calculates budgets and taxes. Microsoft Project lets users define a fiscal year for projects. Aspose.Tasks for Java supports this functionality with properties that allow developers to both read fiscal year properties from existing projects, and set fiscal year properties when creating or working with projects.

The Prj class exposes the FY_START_DATE and FISCAL_YEAR_START properties to manage fiscal year for a project:

Reading Fiscal Year Properties

The FY_START_DATE and FISCAL_YEAR_START properties make it easy to find out what the current fiscal year start date is, and whether fiscal year numbering is used, with Aspose.Tasks.

The following code reads a project’s fiscal year properties and displays them in a console window.

 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(FiscalYearProperties.class);
 4;
 5
 6Project project = new Project(dataDir + "project.mpp");
 7
 8// Display fiscal year properties
 9// Display fiscal year properties
10System.out.println("Fiscal Year Start Date : " + project.get(Prj.FY_START_DATE));
11System.out.println("Fiscal Year Numbering : " + project.get(Prj.FISCAL_YEAR_START));
12
13// ------ Setting Project Fiscal Year Properties
14// Create a project instance
15Project prj = new Project();
16
17// Set fiscal year properties
18prj.set(Prj.FY_START_DATE, Month.July);
19prj.set(Prj.FISCAL_YEAR_START, new NullableBool(true));
20
21// Save the project as XML project file
22prj.save(dataDir + "savedProject.xml", SaveFileFormat.XML);
23
24// Display result of conversion.
25System.out.println("Process completed Successfully");

Weekday Properties

Microsoft Project lets users set a number of different weekday properties, for example, what day a week starts on and how many working days are in a month. Aspose.Tasks support these features through a number of properties that can be used both to read weekday properties and to write them to a project.

Aspose.Tasks has a series of properties, exposed by the Prj class, specifically for managing a project’s weekday properties:

Reading Weekday Properties

The following code reads a project’s weekday properties and writes them to a console window.

 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(WeekdayProperties.class);
 4
 5Project project = new Project(dataDir + "project.mpp");
 6
 7// Display week days properties
 8System.out.println("Week Start Date : " + project.get(Prj.WEEK_START_DAY).toString());
 9System.out.println("Days Per Month : " + project.get(Prj.DAYS_PER_MONTH).toString());
10System.out.println("Minutes Per Day : " + project.get(Prj.MINUTES_PER_DAY).toString());
11System.out.println("Minutes Per Week : " + project.get(Prj.MINUTES_PER_WEEK).toString());

Writing Weekday Properties

To see weekday properties in Microsoft Project:

  1. Open a file.
  2. On the Tools menu, click Options.
  3. Select the Calendar tab. It will look something like the example below.

Viewing weekday properties in Microsoft Project

edit calendar weekday Microsoft Project

The following code writes weekday properties, as shown in the screenshot above, to a project.

 1// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
 2// Create a project instance
 3Project prj = new Project();
 4
 5// Set week days properties
 6project.set(Prj.WEEK_START_DAY, DayType.Monday);
 7project.set(Prj.DAYS_PER_MONTH, 24);
 8project.set(Prj.MINUTES_PER_DAY, 540);
 9project.set(Prj.MINUTES_PER_WEEK, 3240);
10
11// Save the project as XML project file
12prj.save(dataDir + "savedProject.xml", SaveFileFormat.XML);
13
14// Display result of conversion.
15System.out.println("Process completed Successfully");

Currency Properties

Microsoft Project lets users set which currency costs are shown in, in a project. They can define set the currency code, numbers after the decimal point and currency symbol so that costs show in an easy to read and intuitive way. Aspose.Tasks for Java supports these features and provides a series of properties that help developers set and control currency properties. This article explains both how to read currency properties, and how to set them.

Aspose.Tasks for Java provides properties, exposed by the Prj class, for managing currency properties:

Reading Currency Properties

The following piece of code reads a project’s currency properties.

 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(ReadCurrencyProperties.class);
 4
 5// Create a project reader instance
 6Project project = new Project(dataDir + "project.mpp");
 7
 8// Display currency properties
 9System.out.println("Currency Code : " + project.get(Prj.CURRENCY_CODE).toString());
10System.out.println("<br>Currency Digits : " + project.get(Prj.CURRENCY_DIGITS).toString());
11System.out.println("<br>Currency Symbol : " + project.get(Prj.CURRENCY_SYMBOL).toString());
12System.out.println("Currency Symbol Position" + project.get(Prj.CURRENCY_SYMBOL_POSITION).toString());
13
14// Display result of conversion.
15System.out.println("Process completed Successfully");

Writing Currency Properties

The above sample code will create the project file.

To see the currency properties in Microsoft Project:

  1. Open the project file.
  2. On the Tools menu, select Options.
  3. Click the View tab. It will look like the one shown below.

Reading currency properties in Microsoft Project

check currency properties in Microsoft Project

The following example writes currency properties to the 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(SetCurrencyProperties.class);
 4// Create a project instance
 5Project project = new Project();
 6
 7// Set currency properties
 8project.set(Prj.CURRENCY_CODE, "AUD");
 9project.set(Prj.CURRENCY_DIGITS, 2);
10project.set(Prj.CURRENCY_SYMBOL, "$");
11project.set(Prj.CURRENCY_SYMBOL_POSITION, CurrencySymbolPositionType.After);
12// Save the project as XML project file
13project.save(dataDir + "project.xml", SaveFileFormat.XML);
14// Display result of conversion.
15System.out.println("Process completed Successfully");

Setting Attributes for New Tasks

Microsoft Project allows to set default properties for new tasks added. This article explains how to set the default start date for new tasks using Aspose.Tasks for Java API.

The static class Prj exposes the NEW_TASK_START_DATE method that defines the start date for a new task. This property supports the values defined by the TaskStartDateType enumeration type.

To see the task attribute:

  1. Open the file with Microsoft Project.
  2. On the Tools menu, select Options.
  3. Select the Schedule tab. The tab looks like the one shown below.

New tasks set to start on the current date

modify task’s schedule options in Microsoft Project

The following lines of code sets the new task start date.

 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(SetAttributesForNewTasks.class);
 4// create a prject instance
 5Project prj = new Project();
 6// set new task property
 7prj.set(Prj.NEW_TASK_START_DATE, TaskStartDateType.CurrentDate);
 8// save the project in XML format
 9prj.save(dataDir + "project1.xml", SaveFileFormat.XML);
10// Display result of conversion.
11System.out.println("Project file generated Successfully");
Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.