Hello, how are you?
can you help me?
In the new release 18.12, BackgroundColor Black is default.
How can I change this?
using System;
using Aspose.Tasks;
using Aspose.Tasks.Saving;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
License license = new License();
license.SetLicense("Aspose.Tasks.lic");
Project project = new Project("Template.mpp") { CalculationMode = CalculationMode.None };
Task tsk1 = project.RootTask.Children.Add("Task - 01");
Task tsk2 = tsk1.Children.Add("Task - 01.01");
Task tsk3 = tsk2.Children.Add("Task - 01.01.001");
project.Save(@"output.xml", SaveFileFormat.XML);
MPPSaveOptions mppSaveOptions = new MPPSaveOptions
{
WriteViewData = true
};
project.Save(@"output.mpp", mppSaveOptions);
project.Save(@"output.mpp", SaveFileFormat.MPP);
}
}
}
BackgroundColor.png (100.0 KB)
output.zip (21.2 KB)
Template.zip (20.7 KB)
@FabioMartins
Please try the following code sample for setting the text styles:
Project project = new Project(@"D:\188341\Template.mpp") { CalculationMode = CalculationMode.None };
Task tsk1 = project.RootTask.Children.Add("Task - 01");
Task tsk2 = tsk1.Children.Add("Task - 01.01");
Task tsk3 = tsk2.Children.Add("Task - 01.01.001");
GanttChartView view = project.DefaultView 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.BackgroundColor = Color.Red;
tableTextStyle.Field = Field.TaskDurationText;
tableTextStyle.FontStyle = FontStyle.Underline;
view.TableTextStyles.Add(tableTextStyle);
// Add the custom bar style to the custom bar collection of the project view
MPPSaveOptions mppSaveOptions = new MPPSaveOptions
{
WriteViewData = true
};
project.Save(@"D:\188341\output1.mpp", mppSaveOptions);
Moreover, please feel free to write back to us if you need additional information.
Hello,
Attached is the export result:
BackgroundColor2.png (104.5 KB)
output1.zip (21.2 KB)
How could I set a default for all rows?
I would not want to go through all the tasks.
PS: This behavior changed in 18.12.
In 18:11 it was not so.
@FabioMartins
Thank you for your feedback.
We have logged this issue with ID “TASKSNET-2897” for further investigation. You will automatically be informed here once we have more information to share.
@FabioMartins
We have investigated this issue and found that the black default color is a bug and it will be fixed in release 19.1. Now you may use the following workaround:
Project project = new Project(@"D:\Aspose\188341\Template.mpp");
Task tsk1 = project.RootTask.Children.Add("Task - 01");
Task tsk2 = tsk1.Children.Add("Task - 01.01");
Task tsk3 = tsk2.Children.Add("Task - 01.01.001");
GanttChartView view = project.DefaultView as GanttChartView;
Color color = Color.Transparent; // to remove black background.
var textStyle = view.TextStyles.FirstOrDefault(t => t.ItemType == TextItemType.SummaryTasks);
textStyle.BackgroundColor = color;
textStyle = view.TextStyles.FirstOrDefault(t => t.ItemType == TextItemType.NoncriticalTasks);
textStyle.BackgroundColor = color;
textStyle = view.TextStyles.FirstOrDefault(t => t.ItemType == TextItemType.CriticalTasks);
textStyle.BackgroundColor = color;
textStyle = view.TextStyles.FirstOrDefault(t => t.ItemType == TextItemType.MilestoneTasks);
textStyle.BackgroundColor = color;
MPPSaveOptions mppSaveOptions = new MPPSaveOptions
{
WriteViewData = true
};
project.Save(@"D:\Aspose\188341\output1.mpp", mppSaveOptions);
As you can see, in order to set back color for all tasks you should set back color for the following styles:
SummaryTasks, NoncriticalTasks, CriticalTasks, MilestoneTasks
Moreover, please write back to us if you need additional information.