We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Exporting Text Styles

I am trying to add the new text styles as mentioned in your blog here: https://blog.aspose.com/2017/07/31/setting-text-styles-tasks-aspose.tasks-.net-17.7/

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?

@JumpingJezza,

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");
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);
tableTextStyle.BackgroundColor = Color.Blue;
tableTextStyle.Color = Color.Red;
tableTextStyle.Field = Field.TaskName;
tableTextStyle.FontStyle = FontStyle.Bold | FontStyle.Italic;
view.TableTextStyles.Add(tableTextStyle);

// Set second task duration text style
tableTextStyle = new TableTextStyle(2);
tableTextStyle.Color = Color.Yellow;
tableTextStyle.Field = Field.TaskDurationText;
tableTextStyle.FontStyle = FontStyle.Underline;
view.TableTextStyles.Add(tableTextStyle);

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.

  1. 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?

  2. 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?

@JumpingJezza,

  1. Here constructor takes task Unique ID for which style is to be set.

  2. Yes, you are right, the Field value should be Field.Undefined for setting text style of entire 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.

@JumpingJezza,

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)
{
    try
    {
        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)
    {
        Console.WriteLine(ex.Message);
    }
}

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.
eg:

var tableTextStyle = new TableTextStyle(taskId);
tableTextStyle.FontFamily = FontFamily.Families.Single(x => x.Name.Equals("Bodoni MT", StringComparison.OrdinalIgnoreCase));
view.TableTextStyles.Add(tableTextStyle);

@JumpingJezza,

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.