Hi,
i went through API docs, and I was not able to figure out if Aspose Tasks supports getting/setting formatting options of tasks.
E.g. task name was colored with red, and it’s corresponding line in gantt chart was changed to blue - how can I get this info?
Please see my screenshot for example.
Hi,
Thank you for writing to Aspose Support team.
Information about Gantt chart bars can be read for a specific view using the GanttChartView class. You can refer to our documentation article,
Reading Specific Gantt Chart View data, for sample code related to the usage of this and write us back if you have any further query in this regard.
What about first part of my question - formatting of tasks themselves?
Hi,
TableTextStyle can be used to set the color of the task text. Constructor of TableTextStyle takes Uid of the task for which these properties are defined. Please give a try to the following sample code and share the feedback.
Project project = new Project(@“blank2010.mpp”);
project.Set(Prj.NewTasksAreManual,false);
project.RootTask.Children.Add("Task 1");
project.RootTask.Children.Add("Task 2");
GanttChartView view = project.Views.ToList()[1] as GanttChartView;
// Set first task name text style
TableTextStyle tableTextStyle = new TableTextStyle(1);//Text style for task Uid = 1
tableTextStyle.BackgroundColor = Color.Blue;
tableTextStyle.Color = Color.Yellow;
tableTextStyle.Field = Field.TaskName;
tableTextStyle.FontStyle = FontStyle.Bold | FontStyle.Italic;
view.TableTextStyles.Add(tableTextStyle);
// Set second task duration text style
tableTextStyle = new TableTextStyle(2); //Text style for task Uid = 2
tableTextStyle.Color = Color.Yellow;
tableTextStyle.BackgroundColor = Color.Red;
tableTextStyle.Field = Field.TaskDurationText;
tableTextStyle.FontStyle = FontStyle.Underline;
view.TableTextStyles.Add(tableTextStyle);
MPPSaveOptions saveOptions = new MPPSaveOptions();
saveOptions.WriteViewData = true;
project.Save("temp updated.mpp", saveOptions);