TableField

TableField class

Represents a field of a table in a project.

public class TableField

Constructors

NameDescription
TableField()Initializes a new instance of the TableField class.

Properties

NameDescription
AlignData { get; set; }Gets or sets the alignment of data in a table field.
AlignTitle { get; set; }Gets or sets the alignment of the title in a table field.
Field { get; set; }Gets or sets the type of a table field.
Title { get; set; }Gets or sets the title of the field in a table.
Width { get; set; }Gets or sets the width in points of the field column in a table.
WrapHeader { get; set; }Gets or sets a value indicating whether the table column heading can wrap to multiple lines, or if it should be truncated when it exceeds the column width.
WrapText { get; set; }Gets or sets a value indicating whether the column text can wrap to multiple lines, or if it should be truncated when it exceeds the column width. Supported by MSP 2010 version and later.

Examples

Shows how to work with Project’s view and add column to the default view (which is shown when MPP file is opened in MS Project).

// create an empty project without views 
var project = new Project();
project.Set(Prj.Name, "Test View Project");

// Modify the default view (it's a Gantt chart view).
// Or you can select view by name or by View Screen using project.View collection.
var view = (GanttChartView) project.DefaultView;

TableField newColumn = new TableField()
{
    AlignData = HorizontalStringAlignment.Center,
    Title = "My new column",
    Width = 30,
    Field = Field.TaskActualDuration
};

view.Table.TableFields.Add(newColumn);

// WriteViewData flag should be used to persist modifications of view's properties.
project.Save(OutDir + "ModifyView_output.mpp", new Saving.MPPSaveOptions
{
    WriteViewData = true
});

Shows how to read project tables.

var project = new Project(DataDir + "ReadTableData.mpp");

// get the table
var table = project.Tables.ToList()[0];
Console.WriteLine("Print table fields of {0}", table.Name);
Console.WriteLine("Table Fields Count" + table.TableFields.Count);

// display all table fields' information
foreach (var field in table.TableFields)
{
    Console.WriteLine("  Field: " + field.Field);
    Console.WriteLine("  Width: " + field.Width);
    Console.WriteLine("  Title: " + field.Title);
    Console.WriteLine("  Title Alignment: " + field.AlignTitle);
    Console.WriteLine("  Data Alignment: " + field.AlignData);
    Console.WriteLine("  Wrap Header: " + field.WrapHeader);
    Console.WriteLine("  Wrap Text: " + field.WrapText);
    Console.WriteLine();
}

See Also