Aspose::Words::Tables::Table class
Contents
[
Hide
]Table class
Represents a table in a Word document. To learn more, visit the Working with Tables documentation article.
class Table : public Aspose::Words::CompositeNode
Methods
| Method | Description | 
|---|---|
| Accept(System::SharedPtr<Aspose::Words::DocumentVisitor>) override | Accepts a visitor. | 
| AcceptEnd(System::SharedPtr<Aspose::Words::DocumentVisitor>) override | Accepts a visitor for visiting the end of the table. | 
| AcceptStart(System::SharedPtr<Aspose::Words::DocumentVisitor>) override | Accepts a visitor for visiting the start of the table. | 
| AppendChild(T) | |
| AutoFit(Aspose::Words::Tables::AutoFitBehavior) | Resizes the table and cells according to the specified auto fit behavior. | 
| ClearBorders() | Removes all table and cell borders on this table. | 
| ClearShading() | Removes all shading on the table. | 
| Clone(bool) | Creates a duplicate of the node. | 
| ConvertToHorizontallyMergedCells() | Converts cells horizontally merged by width to cells merged by HorizontalMerge. | 
| EnsureMinimum() | If the table has no rows, creates and appends one Row. | 
| get_AbsoluteHorizontalDistance() | Gets or sets absolute horizontal floating table position specified by the table properties, in points. Default value is 0. | 
| get_AbsoluteVerticalDistance() | Gets or sets absolute vertical floating table position specified by the table properties, in points. Default value is 0. | 
| get_Alignment() | Specifies how an inline table is aligned in the document. | 
| get_AllowAutoFit() | Allows Microsoft Word and Aspose.Words to automatically resize cells in a table to fit their contents. | 
| get_AllowCellSpacing() | Gets or sets the “Allow spacing between cells” option. | 
| get_AllowOverlap() | Gets whether a floating table shall allow other floating objects in the document to overlap its extents when displayed. Default value is true. | 
| get_Bidi() | Gets or sets whether this is a right-to-left table. | 
| get_BottomPadding() | Gets or sets the amount of space (in points) to add below the contents of cells. | 
| get_CellSpacing() | Gets or sets the amount of space (in points) between the cells. | 
| get_Count() | Gets the number of immediate children of this node. | 
| get_CustomNodeId() const | Specifies custom node identifier. | 
| get_Description() | Gets or sets description of this table. It provides an alternative text representation of the information contained in the table. | 
| get_DistanceBottom() | Gets or sets distance between table bottom and the surrounding text, in points. | 
| get_DistanceLeft() | Gets or sets distance between table left and the surrounding text, in points. | 
| get_DistanceRight() | Gets or sets distance between table right and the surrounding text, in points. | 
| get_DistanceTop() | Gets or sets distance between table top and the surrounding text, in points. | 
| virtual get_Document() const | Gets the document to which this node belongs. | 
| get_FirstChild() const | Gets the first child of the node. | 
| get_FirstRow() | Returns the first Row node in the table. | 
| get_HasChildNodes() | Returns true if this node has any child nodes. | 
| get_HorizontalAnchor() | Gets the base object from which the horizontal positioning of floating table should be calculated. Default value is Column. | 
| get_IsComposite() override | Returns true as this node can have child nodes. | 
| get_LastChild() const | Gets the last child of the node. | 
| get_LastRow() | Returns the last Row node in the table. | 
| get_LeftIndent() | Gets or sets the value that represents the left indent of the table. | 
| get_LeftPadding() | Gets or sets the amount of space (in points) to add to the left of the contents of cells. | 
| get_NextNode() const | |
| get_NextSibling() | Gets the node immediately following this node. | 
| get_NodeType() const override | Returns Table. | 
| get_ParentNode() | Gets the immediate parent of this node. | 
| get_PreferredWidth() | Gets or sets the table preferred width. | 
| get_PreviousSibling() | Gets the node immediately preceding this node. | 
| get_PrevNode() const | |
| get_Range() | Returns a Range object that represents the portion of a document that is contained in this node. | 
| get_RelativeHorizontalAlignment() | Gets or sets floating table relative horizontal alignment. | 
| get_RelativeVerticalAlignment() | Gets or sets floating table relative vertical alignment. | 
| get_RightPadding() | Gets or sets the amount of space (in points) to add to the right of the contents of cells. | 
| get_Rows() | Provides typed access to the rows of the table. | 
| get_Style() | Gets or sets the table style applied to this table. | 
| get_StyleIdentifier() | Gets or sets the locale independent style identifier of the table style applied to this table. | 
| get_StyleName() | Gets or sets the name of the table style applied to this table. | 
| get_StyleOptions() | Gets or sets bit flags that specify how a table style is applied to this table. | 
| get_TextWrapping() | Gets or sets TextWrapping for table. | 
| get_Title() | Gets or sets title of this table. It provides an alternative text representation of the information contained in the table. | 
| get_TopPadding() | Gets or sets the amount of space (in points) to add above the contents of cells. | 
| get_VerticalAnchor() | Gets the base object from which the vertical positioning of floating table should be calculated. Default value is Margin. | 
| GetAncestor(Aspose::Words::NodeType) | Gets the first ancestor of the specified NodeType. | 
| GetAncestorOf() | |
| GetChild(Aspose::Words::NodeType, int32_t, bool) | Returns an Nth child node that matches the specified type. | 
| GetChildNodes(Aspose::Words::NodeType, bool) | Returns a live collection of child nodes that match the specified type. | 
| GetEnumerator() override | Provides support for the for each style iteration over the child nodes of this node. | 
| GetText() override | Gets the text of this node and of all its children. | 
| GetType() const override | |
| IndexOf(const System::SharedPtr<Aspose::Words::Node>&) | Returns the index of the specified child node in the child node array. | 
| InsertAfter(T, const System::SharedPtr<Aspose::Words::Node>&) | |
| InsertBefore(T, const System::SharedPtr<Aspose::Words::Node>&) | |
| Is(const System::TypeInfo&) const override | |
| IsAncestorNode(const System::SharedPtr<Aspose::Words::Node>&) | |
| NextPreOrder(const System::SharedPtr<Aspose::Words::Node>&) | Gets next node according to the pre-order tree traversal algorithm. | 
| static NodeTypeToString(Aspose::Words::NodeType) | A utility method that converts a node type enum value into a user friendly string. | 
| PrependChild(T) | |
| PreviousPreOrder(const System::SharedPtr<Aspose::Words::Node>&) | Gets the previous node according to the pre-order tree traversal algorithm. | 
| Remove() | Removes itself from the parent. | 
| RemoveAllChildren() | Removes all the child nodes of the current node. | 
| RemoveChild(T) | |
| RemoveSmartTags() | Removes all SmartTag descendant nodes of the current node. | 
| SelectNodes(const System::String&) | Selects a list of nodes matching the XPath expression. | 
| SelectSingleNode(const System::String&) | Selects the first Node that matches the XPath expression. | 
| set_AbsoluteHorizontalDistance(double) | Setter for Aspose::Words::Tables::Table::get_AbsoluteHorizontalDistance. | 
| set_AbsoluteVerticalDistance(double) | Setter for Aspose::Words::Tables::Table::get_AbsoluteVerticalDistance. | 
| set_Alignment(Aspose::Words::Tables::TableAlignment) | Setter for Aspose::Words::Tables::Table::get_Alignment. | 
| set_AllowAutoFit(bool) | Setter for Aspose::Words::Tables::Table::get_AllowAutoFit. | 
| set_AllowCellSpacing(bool) | Setter for Aspose::Words::Tables::Table::get_AllowCellSpacing. | 
| set_Bidi(bool) | Setter for Aspose::Words::Tables::Table::get_Bidi. | 
| set_BottomPadding(double) | Setter for Aspose::Words::Tables::Table::get_BottomPadding. | 
| set_CellSpacing(double) | Setter for Aspose::Words::Tables::Table::get_CellSpacing. | 
| set_CustomNodeId(int32_t) | Setter for Aspose::Words::Node::get_CustomNodeId. | 
| set_Description(const System::String&) | Setter for Aspose::Words::Tables::Table::get_Description. | 
| set_DistanceBottom(double) | Setter for Aspose::Words::Tables::Table::get_DistanceBottom. | 
| set_DistanceLeft(double) | Setter for Aspose::Words::Tables::Table::get_DistanceLeft. | 
| set_DistanceRight(double) | Setter for Aspose::Words::Tables::Table::get_DistanceRight. | 
| set_DistanceTop(double) | Setter for Aspose::Words::Tables::Table::get_DistanceTop. | 
| set_HorizontalAnchor(Aspose::Words::Drawing::RelativeHorizontalPosition) | Setter for Aspose::Words::Tables::Table::get_HorizontalAnchor. | 
| set_LeftIndent(double) | Setter for Aspose::Words::Tables::Table::get_LeftIndent. | 
| set_LeftPadding(double) | Setter for Aspose::Words::Tables::Table::get_LeftPadding. | 
| set_NextNode(const System::SharedPtr<Aspose::Words::Node>&) | |
| set_PreferredWidth(const System::SharedPtr<Aspose::Words::Tables::PreferredWidth>&) | Setter for Aspose::Words::Tables::Table::get_PreferredWidth. | 
| set_PrevNode(const System::SharedPtr<Aspose::Words::Node>&) | |
| set_RelativeHorizontalAlignment(Aspose::Words::Drawing::HorizontalAlignment) | Setter for Aspose::Words::Tables::Table::get_RelativeHorizontalAlignment. | 
| set_RelativeVerticalAlignment(Aspose::Words::Drawing::VerticalAlignment) | Setter for Aspose::Words::Tables::Table::get_RelativeVerticalAlignment. | 
| set_RightPadding(double) | Setter for Aspose::Words::Tables::Table::get_RightPadding. | 
| set_Style(const System::SharedPtr<Aspose::Words::Style>&) | Setter for Aspose::Words::Tables::Table::get_Style. | 
| set_StyleIdentifier(Aspose::Words::StyleIdentifier) | Setter for Aspose::Words::Tables::Table::get_StyleIdentifier. | 
| set_StyleName(const System::String&) | Setter for Aspose::Words::Tables::Table::get_StyleName. | 
| set_StyleOptions(Aspose::Words::Tables::TableStyleOptions) | Setter for Aspose::Words::Tables::Table::get_StyleOptions. | 
| set_TextWrapping(Aspose::Words::Tables::TextWrapping) | Setter for Aspose::Words::Tables::Table::get_TextWrapping. | 
| set_Title(const System::String&) | Setter for Aspose::Words::Tables::Table::get_Title. | 
| set_TopPadding(double) | Setter for Aspose::Words::Tables::Table::get_TopPadding. | 
| set_VerticalAnchor(Aspose::Words::Drawing::RelativeVerticalPosition) | Setter for Aspose::Words::Tables::Table::get_VerticalAnchor. | 
| SetBorder(Aspose::Words::BorderType, Aspose::Words::LineStyle, double, System::Drawing::Color, bool) | Sets the specified table border to the specified line style, width and color. | 
| SetBorders(Aspose::Words::LineStyle, double, System::Drawing::Color) | Sets all table borders to the specified line style, width and color. | 
| SetParent(const System::SharedPtr<Aspose::Words::Node>&) | |
| SetShading(Aspose::Words::TextureIndex, System::Drawing::Color, System::Drawing::Color) | Sets shading to the specified values on whole table. | 
| SetTemplateWeakPtr(uint32_t) override | |
| Table(const System::SharedPtr<Aspose::Words::DocumentBase>&) | Initializes a new instance of the Table class. | 
| ToString(Aspose::Words::SaveFormat) | Exports the content of the node into a string in the specified format. | 
| ToString(const System::SharedPtr<Aspose::Words::Saving::SaveOptions>&) | Exports the content of the node into a string using the specified save options. | 
| static Type() | 
Remarks
Table is a block-level node and can be a child of classes derived from Story or InlineStory.
Table can contain one or more Row nodes.
A minimal valid table needs to have at least one Row.
Examples
Shows how to build a formatted 2x2 table.
auto doc = System::MakeObject<Aspose::Words::Document>();
auto builder = System::MakeObject<Aspose::Words::DocumentBuilder>(doc);
System::SharedPtr<Aspose::Words::Tables::Table> table = builder->StartTable();
builder->InsertCell();
builder->get_CellFormat()->set_VerticalAlignment(Aspose::Words::Tables::CellVerticalAlignment::Center);
builder->Write(u"Row 1, cell 1.");
builder->InsertCell();
builder->Write(u"Row 1, cell 2.");
builder->EndRow();
// While building the table, the document builder will apply its current RowFormat/CellFormat property values
// to the current row/cell that its cursor is in and any new rows/cells as it creates them.
ASSERT_EQ(Aspose::Words::Tables::CellVerticalAlignment::Center, table->get_Rows()->idx_get(0)->get_Cells()->idx_get(0)->get_CellFormat()->get_VerticalAlignment());
ASSERT_EQ(Aspose::Words::Tables::CellVerticalAlignment::Center, table->get_Rows()->idx_get(0)->get_Cells()->idx_get(1)->get_CellFormat()->get_VerticalAlignment());
builder->InsertCell();
builder->get_RowFormat()->set_Height(100);
builder->get_RowFormat()->set_HeightRule(Aspose::Words::HeightRule::Exactly);
builder->get_CellFormat()->set_Orientation(Aspose::Words::TextOrientation::Upward);
builder->Write(u"Row 2, cell 1.");
builder->InsertCell();
builder->get_CellFormat()->set_Orientation(Aspose::Words::TextOrientation::Downward);
builder->Write(u"Row 2, cell 2.");
builder->EndRow();
builder->EndTable();
// Previously added rows and cells are not retroactively affected by changes to the builder's formatting.
ASPOSE_ASSERT_EQ(0, table->get_Rows()->idx_get(0)->get_RowFormat()->get_Height());
ASSERT_EQ(Aspose::Words::HeightRule::Auto, table->get_Rows()->idx_get(0)->get_RowFormat()->get_HeightRule());
ASPOSE_ASSERT_EQ(100, table->get_Rows()->idx_get(1)->get_RowFormat()->get_Height());
ASSERT_EQ(Aspose::Words::HeightRule::Exactly, table->get_Rows()->idx_get(1)->get_RowFormat()->get_HeightRule());
ASSERT_EQ(Aspose::Words::TextOrientation::Upward, table->get_Rows()->idx_get(1)->get_Cells()->idx_get(0)->get_CellFormat()->get_Orientation());
ASSERT_EQ(Aspose::Words::TextOrientation::Downward, table->get_Rows()->idx_get(1)->get_Cells()->idx_get(1)->get_CellFormat()->get_Orientation());
doc->Save(get_ArtifactsDir() + u"DocumentBuilder.BuildTable.docx");
Shows how to create a table.
auto doc = System::MakeObject<Aspose::Words::Document>();
auto table = System::MakeObject<Aspose::Words::Tables::Table>(doc);
doc->get_FirstSection()->get_Body()->AppendChild<System::SharedPtr<Aspose::Words::Tables::Table>>(table);
// Tables contain rows, which contain cells, which may have paragraphs
// with typical elements such as runs, shapes, and even other tables.
// Calling the "EnsureMinimum" method on a table will ensure that
// the table has at least one row, cell, and paragraph.
auto firstRow = System::MakeObject<Aspose::Words::Tables::Row>(doc);
table->AppendChild<System::SharedPtr<Aspose::Words::Tables::Row>>(firstRow);
auto firstCell = System::MakeObject<Aspose::Words::Tables::Cell>(doc);
firstRow->AppendChild<System::SharedPtr<Aspose::Words::Tables::Cell>>(firstCell);
auto paragraph = System::MakeObject<Aspose::Words::Paragraph>(doc);
firstCell->AppendChild<System::SharedPtr<Aspose::Words::Paragraph>>(paragraph);
// Add text to the first cell in the first row of the table.
auto run = System::MakeObject<Aspose::Words::Run>(doc, u"Hello world!");
paragraph->AppendChild<System::SharedPtr<Aspose::Words::Run>>(run);
doc->Save(get_ArtifactsDir() + u"Table.CreateTable.docx");
Shows how to iterate through all tables in the document and print the contents of each cell.
auto doc = System::MakeObject<Aspose::Words::Document>(get_MyDir() + u"Tables.docx");
System::SharedPtr<Aspose::Words::Tables::TableCollection> tables = doc->get_FirstSection()->get_Body()->get_Tables();
ASSERT_EQ(2, tables->ToArray()->get_Length());
for (int32_t i = 0; i < tables->get_Count(); i++)
{
    std::cout << System::String::Format(u"Start of Table {0}", i) << std::endl;
    System::SharedPtr<Aspose::Words::Tables::RowCollection> rows = tables->idx_get(i)->get_Rows();
    // We can use the "ToArray" method on a row collection to clone it into an array.
    ASPOSE_ASSERT_EQ(rows, rows->ToArray());
    ASPOSE_ASSERT_NS(rows, rows->ToArray());
    for (int32_t j = 0; j < rows->get_Count(); j++)
    {
        std::cout << System::String::Format(u"\tStart of Row {0}", j) << std::endl;
        System::SharedPtr<Aspose::Words::Tables::CellCollection> cells = rows->idx_get(j)->get_Cells();
        // We can use the "ToArray" method on a cell collection to clone it into an array.
        ASPOSE_ASSERT_EQ(cells, cells->ToArray());
        ASPOSE_ASSERT_NS(cells, cells->ToArray());
        for (int32_t k = 0; k < cells->get_Count(); k++)
        {
            System::String cellText = cells->idx_get(k)->ToString(Aspose::Words::SaveFormat::Text).Trim();
            std::cout << System::String::Format(u"\t\tContents of Cell:{0} = \"{1}\"", k, cellText) << std::endl;
        }
        std::cout << System::String::Format(u"\tEnd of Row {0}", j) << std::endl;
    }
    std::cout << System::String::Format(u"End of Table {0}\n", i) << std::endl;
}
See Also
- Class CompositeNode
 - Namespace Aspose::Words::Tables
 - Library Aspose.Words for C++