Create MPP File in Python

This topic explains how to create MPP file in Python. It includes the steps as well as a runnable sample code which demonstrates how to create project in Microsoft Project using Python. Moreover, you do not need to install MS Project application to create the MPP files on your end.

Steps to Create MPP File in Python

  1. Configure the system by adding Aspose.Tasks to create MPP files
  2. Initiate an object of the Project class
  3. Add a task and a subtask
  4. Export the output MPP file with the save method

The steps above present how to create project in MS Project using Python. They summarise the program flow from initiating a Project file from scratch, as well as adding tasks and subtasks depending on your needs. Subsequently, the output MPP file is exported while specifying the file paths.

Code to Create MS Project in Python

import aspose.tasks as tasks
# Create a Project file
mppProject = tasks.Project()
# Add task and sub task
task = mppProject.root_task.children.add("Summary1")
subtask = task.children.add("Subtask1")
# Save output MPP file
mppProject.save("CreateMPP.mpp", tasks.saving.SaveFileFormat.MPP)

This code sample showcases the process to create subtask in MS Project in Python. It is a basic version to demonstrate the feature, but it can be enhanced to add different resources, schedules, multiple tasks, subtasks, etc., depending on your requirements. Similarly, you can render the output MPP file to several supported file formats like PDF, Excel, HTML, for quick sharing of the project data.

In this quick guide, you have learned how to create MS Project in Python. Besides, if you need to export MPP to HTML then refer to the article Convert MPP to HTML in Python.

 English