Aspose::Words::Tables::Row class

Row class

Represents a table row. To learn more, visit the Working with Tables documentation article.

class Row : public CompositeNode,
            public IRowAttrSource,
            public Revisions::ITrackableNode

Methods

MethodDescription
Accept(System::SharedPtr<Aspose::Words::DocumentVisitor>) overrideAccepts a visitor.
AcceptEnd(System::SharedPtr<Aspose::Words::DocumentVisitor>) overrideAccepts a visitor for visiting the end of the row.
AcceptStart(System::SharedPtr<Aspose::Words::DocumentVisitor>) overrideAccepts a visitor for visiting the start of the row.
EnsureMinimum()If the Row has no cells, creates and appends one Cell.
GetText() overrideGets the text of all cells in this row including the end of row character.
Row(const System::SharedPtr<Aspose::Words::DocumentBase> &)Initializes a new instance of the Row class.
get_Cells()Provides typed access to the Cell child nodes of the row.
get_FirstCell()Returns the first Cell in the row.
get_Hidden()Gets or sets a flag indicating whether this row is hidden or not.
get_IsFirstRow()True if this is the first row in a table; false otherwise.
get_IsLastRow()True if this is the last row in a table; false otherwise.
get_LastCell()Returns the last Cell in the row.
get_NextRow()Gets the next Row node.
get_NodeType() const overrideReturns Row.
get_ParentTable()Returns the immediate parent table of the row.
get_PreviousRow()Gets the previous Row node.
get_RowFormat()Provides access to the formatting properties of the row.
set_Hidden(bool)Sets a flag indicating whether this row is hidden or not.
virtual AcceptEnd(System::SharedPtr<Aspose::Words::DocumentVisitor>)When implemented in a derived class, calls the VisitXXXEnd method of the specified document visitor.
virtual AcceptStart(System::SharedPtr<Aspose::Words::DocumentVisitor>)When implemented in a derived class, calls the VisitXXXStart method of the specified document visitor.
AppendChild(T)Adds the specified node to the end of the list of child nodes for this node.
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() overrideProvides support for the for each style iteration over the child nodes of this node.
GetText() overrideGets the text of this node and of all its children.
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> &)Inserts the specified node immediately after the specified reference node.
InsertBefore(T, const System::SharedPtr<Aspose::Words::Node> &)Inserts the specified node immediately before the specified reference node.
PrependChild(T)Adds the specified node to the beginning of the list of child nodes for this node.
RemoveAllChildren()Removes all the child nodes of the current node.
RemoveChild(T)Removes the specified child node.
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.
get_Count()Gets the number of immediate children of this node.
get_FirstChild() constGets the first child of the node.
get_HasChildNodes()Returns true if this node has any child nodes.
get_IsComposite() overrideReturns true as this node can have child nodes.
get_LastChild() constGets the last child of the node.
virtual Accept(System::SharedPtr<Aspose::Words::DocumentVisitor>)Accepts a visitor.
Clone(bool)Creates a duplicate of the node.
GetAncestor(Aspose::Words::NodeType)Gets the first ancestor of the specified NodeType.
virtual GetText()Gets the text of this node and of all its children.
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.
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.
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.
get_CustomNodeId() constSpecifies custom node identifier.
virtual get_Document() constGets the document to which this node belongs.
virtual get_IsComposite()Returns true if this node can contain other nodes.
get_NextSibling()Gets the node immediately following this node.
virtual get_NodeType() constGets the type of this node.
get_ParentNode()Gets the immediate parent of this node.
get_PreviousSibling()Gets the node immediately preceding this node.
get_Range()Returns a Range object that represents the portion of a document that is contained in this node.
set_CustomNodeId(int32_t)Specifies custom node identifier.

Remarks

Row can only be a child of a Table.

Row can contain one or more Cell nodes.

A minimal valid row needs to have at least one Cell.

Examples

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>(System::String(get_MyDir() + u"Tables.docx"));
System::SharedPtr<Aspose::Words::Tables::TableCollection> tables = doc->get_FirstSection()->get_Body()->get_Tables();

ASSERT_EQ(tables->ToArray()->get_Length(), 2);

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->ToArray(), rows);
    ASSERT_FALSE(System::Object::ReferenceEquals(rows->ToArray(), rows));

    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->ToArray(), cells);
        ASSERT_FALSE(System::Object::ReferenceEquals(cells->ToArray(), cells));

        for (int32_t k = 0; k < cells->get_Count(); k++)
        {
            System::String cellText = cells->idx_get(k)->ToString(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