This brief guide covers how to create MPP file in Java. It contains the stepwise algorithm and a runnable code snippet demonstrating how to create project in Microsoft Project using Java. Furthermore, it does not require installing MS Project software to create the MPP files in your applications.
Steps to Create MPP File in Java
- Prepare the environment by installing Aspose.Tasks to create MPP files
- Create an instance of the Project class
- Create a task and add a subtask to it
- Render the generated MPP file using the save method
These steps outline how to create project in MS Project using Java. They present the program algorithm from initiating a Project file from scratch and subsequently add tasks and their respective subtasks based on your requirements. Finally, write the created MPP file to the disk or a stream.
Code to Create MS Project in Java
// Create project | |
com.aspose.tasks.Project project = new com.aspose.tasks.Project(); | |
// Add task | |
com.aspose.tasks.Task task = project.getRootTask().getChildren().add("Summary1"); | |
// Add sub task | |
com.aspose.tasks.Task subtask = task.getChildren().add("Subtask1"); | |
// Save output project | |
project.save("Project.mpp", com.aspose.tasks.SaveFileFormat.Mpp); |
This code snippet presents a basic version to create subtask in MS Project in Java. However, you may further improvise it by adding workdays, multiple tasks and subtasks, resources, etc., to meet your requirements. Furthermore, the generated project file can also be exported to different file formats, including HTML, PDF, Excel, etc., as per your needs.
In this quick tutorial, you have explored how to create MS Project in Java. Whereas, if you want to render MPP to an HTML webpage, then read the article Convert MPP to HTML in Java.