Working with Formulas

Formulas in Microsoft Project allow you to automate calculations, create custom logic, and enhance reporting capabilities.
Using Aspose.Tasks for .NET, developers can programmatically work with formulas in MPP files — from defining and editing to saving them back to the project.

This section provides an overview of how to use formulas in Aspose.Tasks, including:

Getting Started

To start working with formulas in Aspose.Tasks:

  1. Load an existing project or create a new one.
  2. Access the required custom field definition.
  3. Assign a formula to the field.
  4. Save the project back to MPP format.

Example: Assigning a Formula to a Task Field

 1class Program
 2{
 3    static void Main()
 4    {
 5        // Load project
 6        var project = new Project("input.mpp");
 7
 8        // Define a custom task field
 9        ExtendedAttributeDefinition attr = ExtendedAttributeDefinition.CreateTaskDefinition(
10            CustomFieldType.Number,
11            ExtendedAttributeTask.Number1,
12            "CustomFormulaField");
13
14        project.ExtendedAttributes.Add(attr);
15
16        // Assign a formula to the field
17        attr.Formula = "[Actual Duration] / [Duration]";
18
19        // Save result
20        project.Save("output.mpp", SaveFileFormat.Mpp);
21    }
22}

In this example, the formula calculates a custom value based on the task’s duration and standard rate.

Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.