How to Extract Microsoft Project Metadata in Java

This quick tutorial provides steps and code to extract Microsoft Project metadata in Java. An MPP Project file can have a lot of metadata information like author, calendar, comments, creation date, currency code, date format, manager name, project name, and many more. Hence, using this tutorial you will not only get information on how to extract Microsoft Project metadata in Java but also get hints about setting project metadata.

Steps to Extract Microsoft Project Metadata in Java

  1. Using the Maven Repository, add a reference to Aspose.Tasks in your project to fetch project metadata
  2. Using the Project class object, open the MPP file whose metadata is to be fetched
  3. Access the project metadata from the loaded file using the Prj enumerator
  4. Display the project metadata information on the console

These steps describe the process to get MS Project metadata in Java by loading it into the Project class object and then using the get() method of Project class to access any of the metadata properties with the Prj enum value. These properties are stored in the string variables and displayed on the console. In the same manner, you can set metadata by providing the Prj enum value along with the desired value to be set.

Code to Retrieve MPP File Metadata in Java

import com.aspose.barcode.License;
import com.aspose.tasks.Prj;
import com.aspose.tasks.Project;
public class ExtractMicrosoftProjectMetadataInJava {
public static void main(String[] args) throws Exception{ // main function for the ExtractMicrosoftProjectMetadataInJava class
// Set Aspose.Tasks license to avoid trial version limitations before featching the Microsoft project metadata
License projectLicense = new License();
projectLicense.setLicense("Aspose.Tasks.lic");
// Load the sample MPP file whose metadata is to be fetched
Project MPPFile = new Project("InputMPPFileForMetadata.mpp");
// Declare a few string variables to store metadata information fetched from the project
String MPPAuthor, MPPCategory, MPPCompany, MPPComments;
// Fetch the desired properties from the project metadata collection in the loaded MPP file
MPPAuthor = MPPFile.get(Prj.AUTHOR);
MPPCategory = MPPFile.get(Prj.CATEGORY);
MPPCompany = MPPFile.get(Prj.COMPANY);
MPPComments = MPPFile.get(Prj.COMMENTS);
// Format a string to display the project metadata information
String metadata = String.format("Author:%s, Catgory:%s, Company:%s, Comments:%s",MPPAuthor, MPPCategory, MPPCompany, MPPComments);
// Print the project metadata on the console
System.out.println(metadata);
}
}

This code loads the sample MPP file into Project class object from the disc and retrieves MPP file metadata using Java. The Prj class contains around 80 properties that can be accessed against a particular project. The same Prj class can be used to set these properties.

We have learned to extract MPP document metadata in Java by following the above steps. However, if you are looking for converting the MS Project file to some other format, refer to the article on how to convert Microsoft Project file to XPS in Java.

 English