Percentage Complete Calculations

Microsoft Project shows the percentage of a task that’s been completed. The percentage can be added manually, by a project manager, or automatically calculated by the application. Aspose.Tasks for C++ supports several percentage calculations related to tasks.


The Tsk class exposes a number of properties used to calculate percentages:

To see the physical percentage complete in Microsoft Project:

  1. On the Task Entry form, from the Insert menu, select Column.
  2. Add the column.

To see the completed percentage in Microsoft Project:

  1. On the Task Entry form, double-click the desired column.

Getting Percentages

The following code example demonstrates how to get the percentages of work relating to tasks.

 1// Create project instance
 2System::String dataDir = RunExamples::GetDataDir(System::Reflection::MethodBase::GetCurrentMethod(ASPOSE_CURRENT_FUNCTION)->get_DeclaringType().get_FullName());
 3System::SharedPtr<Project> project1 = System::MakeObject<Project>(dataDir + u"TaskPercentageCompletion.mpp");
 5// Access tasks and display percentage completion
 6auto tasks = project1->get_RootTask()->get_Children();
 9    auto tsk1_enumerator = (tasks)->GetEnumerator();
10    decltype(tsk1_enumerator->get_Current()) tsk1;
11    while (tsk1_enumerator->MoveNext() && (tsk1 = tsk1_enumerator->get_Current(), true))
12    {
13        System::Console::WriteLine(tsk1->Get<int32_t>(Tsk::PercentComplete()));
14        System::Console::WriteLine(System::Convert::ToString(tsk1->Get<int32_t>(Tsk::PercentWorkComplete())));
15        System::Console::WriteLine(System::Convert::ToString(tsk1->Get<int32_t>(Tsk::PhysicalPercentComplete())));
16    }

Changing Task Progress

Aspose.Tasks for C++ API supports changing a task’s progress in terms of its percentage completion through the Task class’ SetPercentComplete() method. This method takes an integer argument as input for the percentage work completed.

The following piece of code shows how to change the progress of a task.

1System::SharedPtr<Project> project = System::MakeObject<Project>();
2System::Console::WriteLine(u"Project Calculation mode is Automatic: {0}", System::ObjectExt::Box<bool>(System::ObjectExt::Equals(project->get_CalculationMode(), Aspose::Tasks::CalculationMode::Automatic)));
4System::SharedPtr<Task> task = project->get_RootTask()->get_Children()->Add(u"Task");
5task->Set<Duration>(Tsk::Duration(), project->GetDuration(2));
6task->Set<int32_t>(Tsk::PercentComplete(), 50);
Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.