Class Table

Class Table

Namespace: Aspose.Note
Assembly: Aspose.Note.dll (25.6.0)

Represents a table.

public sealed class Table : CompositeNode<Tablerow>, ICompositeNode<Tablerow>, ICompositeNode, IEnumerable<Tablerow>, IEnumerable, IOutlineElementChildNode, ITaggable, INode
   {
       public override Tablerow AddNewChild(Tablerow child, bool checkForDuplicate)
       {
           return base.AddNewChild(child, checkForDuplicate);
       }
       public void Accept(IVisitor visitor)
       {
           visitor.VisitTable(this);
       }
       IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator();
       IEnumerator<Tablerow> IEnumerable<Tablerow>.GetEnumerator() => this.GetEnumerator();
   }

Inheritance

object Node CompositeNodeBase CompositeNode Table

Implements

ICompositeNode , ICompositeNode , IEnumerable , IEnumerable , IOutlineElementChildNode , ITaggable , INode

Inherited Members

CompositeNode.GetEnumerator() , CompositeNode.InsertChild(int, T1) , CompositeNode.InsertChildrenRange(int, IEnumerable) , CompositeNode.InsertChildrenRange(int, params TableRow[]) , CompositeNode.AppendChildFirst(T1) , CompositeNode.AppendChildLast(T1) , CompositeNode.RemoveChild(T1) , CompositeNode.Accept(DocumentVisitor) , CompositeNode.GetChildNodes(NodeType) , CompositeNode.GetChildNodes() , CompositeNode.IsComposite , CompositeNode.FirstChild , CompositeNode.LastChild , CompositeNodeBase.GetChildNodes(NodeType) , CompositeNodeBase.GetChildNodes() , Node.Accept(DocumentVisitor) , Node.Document , Node.IsComposite , Node.NodeType , Node.ParentNode , Node.PreviousSibling , Node.NextSibling , object.GetType() , object.ToString() , object.Equals(object?) , object.Equals(object?, object?) , object.ReferenceEquals(object?, object?) , object.GetHashCode()

Examples

Shows how to get text from every table’s row.

string dataDir = RunExamples.GetDataDir_Tables();
   Document document = new Document(dataDir + "Sample1.one");
   IList<Table> nodes = document.GetChildNodes<Table>();
   foreach (Table table in nodes)
   {
      foreach (TableRow row in table)
      {
         string text = string.Join(Environment.NewLine,
            row.GetChildNodes<RichText>()
               .Select(e => e.Text)) + Environment.NewLine;
         Console.WriteLine(text);
      }
   }

Shows how to get text from a table.

string dataDir = RunExamples.GetDataDir_Tables();
   Document document = new Document(dataDir + "Sample1.one");
   IList<Table> nodes = document.GetChildNodes<Table>();
   int tblCount = 0;
   foreach (Table table in nodes)
   {
       tblCount++;
       Console.WriteLine("table # " + tblCount);
       string text = string.Join(Environment.NewLine, table.GetChildNodes<RichText>().Select(e => e.Text));
       Console.WriteLine(text);
   }

Shows how to get text from a table’s cells.

string dataDir = RunExamples.GetDataDir_Tables();
   Document document = new Document(dataDir + "Sample1.one");
   IList<Table> nodes = document.GetChildNodes<Table>();
   foreach (Table table in nodes)
   {
       foreach (TableRow row in table)
       {
           IList<TableCell> cells = row.GetChildNodes<TableCell>();
           string text = string.Join(Environment.NewLine,
                                     cells.Select(cell => cell.GetChildNodes<RichText>().Select(e => e.Text))
                                        .Select(cellsInRow => string.Join(Environment.NewLine, cellsInRow))
                                        .ToArray()) + Environment.NewLine;
           Console.WriteLine(text);
       }
   }

Shows how to set a background color for a cell.

Document doc = new Document();
   TableCell cell11 = new TableCell(doc);
      cell11.AppendChildLast(InsertTable.GetOutlineElementWithText(doc, "Small text"));
      cell11.BackgroundColor = Color.Coral;
   TableRow row = new TableRow(doc);
      row.AppendChildLast(cell11);
   Table table = new Table(doc)
   {
       IsBordersVisible = true,
       Columns = { new TableColumn() { Width = 200 } }
   };
      table.AppendChildLast(row);
   OutlineElement oe = new OutlineElement(doc);
      oe.AppendChildLast(table);
   Outline o = new Outline(doc);
      o.AppendChildLast(oe);
   Page page = new Page(doc);
      page.AppendChildLast(o);
   doc.AppendChildLast(page);
   doc.Save(Path.Combine(RunExamples.GetDataDir_Tables(), "SettingCellBackGroundColor.pdf"));

Shows how to add new table with tag.

string dataDir = RunExamples.GetDataDir_Tags();
   Document doc = new Document();
   Aspose.Note.Page page = new Aspose.Note.Page(doc);
   TableRow row = new TableRow(doc);
   TableCell cell = new TableCell(doc);
   cell.AppendChildLast(InsertTable.GetOutlineElementWithText(doc, "Single cell."));
   row.AppendChildLast(cell);
   Table table = new Table(doc)
   {
      IsBordersVisible = true
   };
   table.Columns.Add(new TableColumn { Width = 70 });
   table.AppendChildLast(row);
   table.Tags.Add(NoteTag.CreateQuestionMark());
   OutlineElement outlineElem = new OutlineElement(doc);
   outlineElem.AppendChildLast(table);
   Outline outline = new Outline(doc);
   outline.AppendChildLast(outlineElem);
   page.AppendChildLast(outline);
   doc.AppendChildLast(page);
   dataDir += "AddTableNodeWithTag_out.one";
   doc.Save(dataDir);

Shows how to create a table with a locked column.

string dataDir = RunExamples.GetDataDir_Tables();
   Document doc = new Document();
   Aspose.Note.Page page = new Aspose.Note.Page(doc);
   TableRow row1 = new TableRow(doc);
   TableCell cell11 = new TableCell(doc);
   cell11.AppendChildLast(InsertTable.GetOutlineElementWithText(doc, "Small text"));
   row1.AppendChildLast(cell11);
   TableRow row2 = new TableRow(doc);
   TableCell cell21 = new TableCell(doc);
   cell21.AppendChildLast(InsertTable.GetOutlineElementWithText(doc, "Long   text    with    several   words and    spaces."));
   row2.AppendChildLast(cell21);
   Table table = new Table(doc)
   {
       IsBordersVisible = true,
       Columns =
       {
           new TableColumn { Width = 70, LockedWidth = true }
       }
   };
   table.AppendChildLast(row1);
   table.AppendChildLast(row2);
   Outline outline = new Outline(doc);
   OutlineElement outlineElem = new OutlineElement(doc);
   outlineElem.AppendChildLast(table);
   outline.AppendChildLast(outlineElem);
   page.AppendChildLast(outline);
   doc.AppendChildLast(page);
   dataDir += "CreateTableWithLockedColumns_out.one";
   doc.Save(dataDir);

Shows how to create a new table.

string dataDir = RunExamples.GetDataDir_Tables();
   Document doc = new Document();
   Aspose.Note.Page page = new Aspose.Note.Page(doc);
   TableRow row1 = new TableRow(doc);
   TableRow row2 = new TableRow(doc);
   TableCell cell11 = new TableCell(doc);
   TableCell cell12 = new TableCell(doc);
   TableCell cell13 = new TableCell(doc);
   TableCell cell21 = new TableCell(doc);
   TableCell cell22 = new TableCell(doc);
   TableCell cell23 = new TableCell(doc);
   cell11.AppendChildLast(GetOutlineElementWithText(doc, "cell_1.1"));
   cell12.AppendChildLast(GetOutlineElementWithText(doc, "cell_1.2"));
   cell13.AppendChildLast(GetOutlineElementWithText(doc, "cell_1.3"));
   cell21.AppendChildLast(GetOutlineElementWithText(doc, "cell_2.1"));
   cell22.AppendChildLast(GetOutlineElementWithText(doc, "cell_2.2"));
   cell23.AppendChildLast(GetOutlineElementWithText(doc, "cell_2.3"));
   row1.AppendChildLast(cell11);
   row1.AppendChildLast(cell12);
   row1.AppendChildLast(cell13);
   row2.AppendChildLast(cell21);
   row2.AppendChildLast(cell22);
   row2.AppendChildLast(cell23);
   Table table = new Table(doc)
   {
       IsBordersVisible = true,
       Columns =
       {
           new TableColumn { Width = 200 },
           new TableColumn { Width = 200 },
           new TableColumn { Width = 200 }
       }
   };
   table.AppendChildLast(row1);
   table.AppendChildLast(row2);
   Outline outline = new Outline(doc);
   OutlineElement outlineElem = new OutlineElement(doc);
   outlineElem.AppendChildLast(table);
   outline.AppendChildLast(outlineElem);
   page.AppendChildLast(outline);
   doc.AppendChildLast(page);
   dataDir += "InsertTable_out.one";
   doc.Save(dataDir);

Constructors

Table()

public Table
   {
   }

Properties

Columns

Gets the columns of the table.

public IList<tablecolumn> Columns
   {
      get;
   }

Property Value

IList < TableColumn >

Examples

Shows how to set a background color for a cell.

Document doc = new Document();
   TableCell cell11 = new TableCell(doc);
      cell11.AppendChildLast(InsertTable.GetOutlineElementWithText(doc, "Small text"));
      cell11.BackgroundColor = Color.Coral;
   TableRow row = new TableRow(doc);
      row.AppendChildLast(cell11);
   Table table = new Table(doc)
   {
       IsBordersVisible = true,
       Columns = { new TableColumn() { Width = 200 } }
   };
      table.AppendChildLast(row);
   OutlineElement oe = new OutlineElement(doc);
      oe.AppendChildLast(table);
   Outline o = new Outline(doc);
      o.AppendChildLast(oe);
   Page page = new Page(doc);
      page.AppendChildLast(o);
   doc.AppendChildLast(page);
   doc.Save(Path.Combine(RunExamples.GetDataDir_Tables(), "SettingCellBackGroundColor.pdf"));

Shows how to add new table with tag.

string dataDir = RunExamples.GetDataDir_Tags();
   Document doc = new Document();
   Aspose.Note.Page page = new Aspose.Note.Page(doc);
   TableRow row = new TableRow(doc);
   TableCell cell = new TableCell(doc);
   cell.AppendChildLast(InsertTable.GetOutlineElementWithText(doc, "Single cell."));
   row.AppendChildLast(cell);
   Table table = new Table(doc)
   {
       IsBordersVisible = true
   };
   table.Columns.Add(new TableColumn { Width = 70 });
   table.AppendChildLast(row);
   table.Tags.Add(NoteTag.CreateQuestionMark());
   Outline outline = new Outline(doc);
   OutlineElement outlineElem = new OutlineElement(doc);
   outlineElem.AppendChildLast(table);
   outline.AppendChildLast(outlineElem);
   page.AppendChildLast(outline);
   doc.AppendChildLast(page);
   dataDir += "AddTableNodeWithTag_out.one";
   doc.Save(dataDir);

Shows how to create a table with a locked column.

string dataDir = RunExamples.GetDataDir_Tables();
   Document doc = new Document();
   Aspose.Note.Page page = new Aspose.Note.Page(doc);
   TableRow row1 = new TableRow(doc);
      TableCell cell11 = new TableCell(doc);
         cell11.AppendChildLast(InsertTable.GetOutlineElementWithText(doc, "Small text"));
      row1.AppendChildLast(cell11);
   TableRow row2 = new TableRow(doc);
      TableCell cell21 = new TableCell(doc);
         cell21.AppendChildLast(InsertTable.GetOutlineElementWithText(doc, "Long text with several words and spaces."));
      row2.AppendChildLast(cell21);
   Table table = new Table(doc)
   {
       IsBordersVisible = true,
       Columns = { new TableColumn { Width = 70, LockedWidth = true } }
   };
      table.AppendChildLast(row1);
      table.AppendChildLast(row2);
   Outline outline = new Outline(doc);
      OutlineElement outlineElem = new OutlineElement(doc);
         outlineElem.AppendChildLast(table);
      outline.AppendChildLast(outlineElem);
   page.AppendChildLast(outline);
   doc.AppendChildLast(page);
   dataDir += "CreateTableWithLockedColumns_out.one";
   doc.Save(dataDir);

Shows how to create a new table.

string dataDir = RunExamples.GetDataDir_Tables();
   Document doc = new Document();
   Aspose.Note.Page page = new Aspose.Note.Page(doc);
   TableRow row1 = new TableRow(doc);
   TableCell cell11 = new TableCell(doc);
   TableCell cell12 = new TableCell(doc);
   TableCell cell13 = new TableCell(doc);
   cell11.AppendChildLast(GetOutlineElementWithText(doc, "cell_1.1"));
   cell12.AppendChildLast(GetOutlineElementWithText(doc, "cell_1.2"));
   cell13.AppendChildLast(GetOutlineElementWithText(doc, "cell_1.3"));
   row1.AppendChildLast(cell11);
   row1.AppendChildLast(cell12);
   row1.AppendChildLast(cell13);
   TableRow row2 = new TableRow(doc);
   TableCell cell21 = new TableCell(doc);
   TableCell cell22 = new TableCell(doc);
   TableCell cell23 = new TableCell(doc);
   cell21.AppendChildLast(GetOutlineElementWithText(doc, "cell_2.1"));
   cell22.AppendChildLast(GetOutlineElementWithText(doc, "cell_2.2"));
   cell23.AppendChildLast(GetOutlineElementWithText(doc, "cell_2.3"));
   row2.AppendChildLast(cell21);
   row2.AppendChildLast(cell22);
   row2.AppendChildLast(cell23);
   Table table = new Table(doc)
   {
       IsBordersVisible = true,
       Columns = { new TableColumn { Width = 200 }, new TableColumn { Width = 200 }, new TableColumn { Width = 200 } }
   };
   table.AppendChildLast(row1);
   table.AppendChildLast(row2);
   Outline outline = new Outline(doc);
   OutlineElement outlineElem = new OutlineElement(doc);
   outlineElem.AppendChildLast(table);
   outline.AppendChildLast(outlineElem);
   page.AppendChildLast(outline);
   doc.AppendChildLast(page);
   dataDir = dataDir + "InsertTable_out.one";
   doc.Save(dataDir);

IsBordersVisible

Gets or sets a value indicating whether the table border is visible.

public bool IsBordersVisible
{
    get;
    private set;
}

Property Value

bool

Examples

Shows how to set a background color for a cell.

Document doc = new Document();
   TableCell cell11 = new TableCell(doc);
      cell11.AppendChildLast(InsertTable.GetOutlineElementWithText(doc, "Small text"));
      cell11.BackgroundColor = Color.Coral;
   TableRow row = new TableRow(doc);
      row.AppendChildLast(cell11);
   Table table = new Table(doc)
   {
      IsBordersVisible = true,
      Columns = { new TableColumn() { Width = 200 } }
   };
      table.AppendChildLast(row);
   OutlineElement oe = new OutlineElement(doc);
      oe.AppendChildLast(table);
   Outline o = new Outline(doc);
      o.AppendChildLast(oe);
   Page page = new Page(doc);
      page.AppendChildLast(o);
   doc.AppendChildLast(page);
   doc.Save(Path.Combine(RunExamples.GetDataDir_Tables(), "SettingCellBackGroundColor.pdf"));

Shows how to add new table with tag.

string dataDir = RunExamples.GetDataDir_Tags();
   Document doc = new Document();
   Aspose.Note.Page page = new Aspose.Note.Page(doc);
   TableRow row = new TableRow(doc);
   TableCell cell = new TableCell(doc);
   cell.AppendChildLast(InsertTable.GetOutlineElementWithText(doc, "Single cell."));
   row.AppendChildLast(cell);
   Table table = new Table(doc)
   {
       IsBordersVisible = true
   };
   table.Columns.Add(new TableColumn { Width = 70 });
   table.AppendChildLast(row);
   table.Tags.Add(NoteTag.CreateQuestionMark());
   Outline outline = new Outline(doc);
   OutlineElement outlineElem = new OutlineElement(doc);
   outlineElem.AppendChildLast(table);
   outline.AppendChildLast(outlineElem);
   page.AppendChildLast(outline);
   doc.AppendChildLast(page);
   dataDir += "AddTableNodeWithTag_out.one";
   doc.Save(dataDir);

Shows how to create a table with a locked column.

string dataDir = RunExamples.GetDataDir_Tables();
   Document doc = new Document();
   Aspose.Note.Page page = new Aspose.Note.Page(doc);
   TableRow row1 = new TableRow(doc);
   TableCell cell11 = new TableCell(doc);
   cell11.AppendChildLast(InsertTable.GetOutlineElementWithText(doc, "Small text"));
   row1.AppendChildLast(cell11);
   TableRow row2 = new TableRow(doc);
   TableCell cell21 = new TableCell(doc);
   cell21.AppendChildLast(InsertTable.GetOutlineElementWithText(doc, "Long text with several words and spaces."));
   row2.AppendChildLast(cell21);
   Table table = new Table(doc)
   {
       IsBordersVisible = true
   };
   table.Columns.Add(new TableColumn() { Width = 70, LockedWidth = true });
   table.AppendChildLast(row1);
   table.AppendChildLast(row2);
   Outline outline = new Outline(doc);
   OutlineElement outlineElem = new OutlineElement(doc);
   outlineElem.AppendChildLast(table);
   outline.AppendChildLast(outlineElem);
   page.AppendChildLast(outline);
   doc.AppendChildLast(page);
   dataDir += "CreateTableWithLockedColumns_out.one";
   doc.Save(dataDir);

Shows how to create a new table.

string dataDir = RunExamples.GetDataDir_Tables();
   Document doc = new Document();
   Aspose.Note.Page page = new Aspose.Note.Page(doc);
   TableRow row1 = new TableRow(doc);
   TableRow row2 = new TableRow(doc);
   TableCell cell11 = new TableCell(doc);
   TableCell cell12 = new TableCell(doc);
   TableCell cell13 = new TableCell(doc);
   TableCell cell21 = new TableCell(doc);
   TableCell cell22 = new TableCell(doc);
   TableCell cell23 = new TableCell(doc);
   cell11.AppendChildLast(GetOutlineElementWithText(doc, "cell_1.1"));
   cell12.AppendChildLast(GetOutlineElementWithText(doc, "cell_1.2"));
   cell13.AppendChildLast(GetOutlineElementWithText(doc, "cell_1.3"));
   cell21.AppendChildLast(GetOutlineElementWithText(doc, "cell_2.1"));
   cell22.AppendChildLast(GetOutlineElementWithText(doc, "cell_2.2"));
   cell23.AppendChildLast(GetOutlineElementWithText(doc, "cell_2.3"));
   row1.AppendChildLast(cell11);
   row1.AppendChildLast(cell12);
   row1.AppendChildLast(cell13);
   row2.AppendChildLast(cell21);
   row2.AppendChildLast(cell22);
   row2.AppendChildLast(cell23);
   Table table = new Table(doc)
   {
       IsBordersVisible = true,
       Columns =
       {
           new TableColumn { Width = 200 },
           new TableColumn { Width = 200 },
           new TableColumn { Width = 200 }
       }
   };
   table.AppendChildLast(row1);
   table.AppendChildLast(row2);
   Outline outline = new Outline(doc);
   OutlineElement outlineElem = new OutlineElement(doc);
   outlineElem.AppendChildLast(table);
   outline.AppendChildLast(outlineElem);
   page.AppendChildLast(outline);
   doc.AppendChildLast(page);
   dataDir += "InsertTable_out.one";
   doc.Save(dataDir);

LastModifiedTime

Gets or sets the last modified time.

public DateTime LastModifiedTime
    {
        get;
        private set;
    }

Property Value

DateTime

Tags

Gets the list of all tags of a paragraph.

public List<Tag> Tags { get; } // Standard naming convention for types is PascalCase (Capitalizing first letter of each word)

Property Value

List < ITag >

Methods

Accept(DocumentVisitor)

Accepts the visitor of the node.

public override void Accept(Aspose.Words.DocumentVisitor visitor)
{
}

Parameters

visitor DocumentVisitor

The object of a class derived from the Aspose.Note.DocumentVisitor.

 English