I am trying to add the new text styles as mentioned in your blog here: Set Text Styles of Tasks in MS Projects (MPP) using C#
However, the styles do not appear in the exported project file. I have attached a demo solution that demonstrates this Exporter.zip (40.0 KB). I have also tried adding the styles after recalculating and I get the same result. I am using Microsoft Project 2016 to open the exported file.
Am I doing something wrong, or is this a bug?
Thank you for contacting Aspose support team.
You may please refer following sample code to modify your code for creating new text styles and share the feedback.
string path = @"..\debug\";
Project project = new Project(@"blank2010.mpp");
GanttChartView view = project.Views.ToList() as GanttChartView;
// Set first task name text style
TableTextStyle tableTextStyle = new TableTextStyle(1);
tableTextStyle.BackgroundColor = Color.Blue;
tableTextStyle.Color = Color.Red;
tableTextStyle.Field = Field.TaskName;
tableTextStyle.FontStyle = FontStyle.Bold | FontStyle.Italic;
// Set second task duration text style
tableTextStyle = new TableTextStyle(2);
tableTextStyle.Color = Color.Yellow;
tableTextStyle.Field = Field.TaskDurationText;
tableTextStyle.FontStyle = FontStyle.Underline;
MPPSaveOptions saveOptions = new MPPSaveOptions();
saveOptions.WriteViewData = true;
project.Save(path + "tempupdated.mpp", saveOptions);
Sorry but that code doesn’t work in the project I attached.
What value have you used to initialise the TableTextStyle? new TableTextStyle(1); <-- What is 1? The row index (0 or 1 based)? Is it the id of the task? or the Uid of the task?
In my example I specifically included a TableTextStyle that applied to the entire row. Reading from an mpp file I can see for these cases that the Field = Field.Undefined. Is this the appropriate way to SET a TableTextStyle to all fields in a row?
OK thanks for confirming that. That is what I assumed.
Are you able to run the project I attached originally? The code there is similar - but the styles do not appear in the exported file. I am viewing it with Project 2016.
Thank you for the feedback.
You may please use MPPSaveOptions and set WriteViewData to true for saving the text style in the file as shown in the following example:
void btnExport_Click(object sender, EventArgs e)
var exporter = new WriteExportFile();
var project = exporter.RunExport();
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
using (var fileStream = new FileStream(saveFileDialog1.FileName, FileMode.Create, FileAccess.Write))
MPPSaveOptions saveOptions = new MPPSaveOptions();//Add this line
saveOptions.WriteViewData = true;//Add this line
project.Save(fileStream, saveOptions);//Modify this line
catch (Exception ex)
Thank you for that! It works now. Its funny I had tried that, but not at the same time as using the uid instead of the id.
Just 1 thing still doesn’t seem to work. If I set the font family it seems to ignore it. No matter what I set the font to it uses Calibri.
var tableTextStyle = new TableTextStyle(taskId);
tableTextStyle.FontFamily = FontFamily.Families.Single(x => x.Name.Equals("Bodoni MT", StringComparison.OrdinalIgnoreCase));
This issue is re-produced and logged under Id:TASKSNET-2121 for further investigation by the product team. You will be automatically notified once any update is received in this regard.