Aspose::Words::Tables::Row Class Reference

Detailed Description

Represents a table row.

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 simple table.

auto doc = MakeObject<Document>();
// Tables are placed in the body of a document
auto table = MakeObject<Table>(doc);
doc->get_FirstSection()->get_Body()->AppendChild(table);
// Tables contain rows, which contain cells,
// which contain contents such as paragraphs, runs and even other tables
// Calling table.EnsureMinimum will also make sure that a table has at least one row, cell and paragraph
auto firstRow = MakeObject<Row>(doc);
table->AppendChild(firstRow);
auto firstCell = MakeObject<Cell>(doc);
firstRow->AppendChild(firstCell);
auto paragraph = MakeObject<Paragraph>(doc);
firstCell->AppendChild(paragraph);
auto run = MakeObject<Run>(doc, u"Hello world!");
paragraph->AppendChild(run);
doc->Save(ArtifactsDir + u"Table.CreateTable.docx");

Shows how to iterate through all tables in the document and display the content from each cell.

auto doc = MakeObject<Document>(MyDir + u"Tables.docx");
// Here we get all tables from the Document node. You can do this for any other composite node
// which can contain block level nodes. For example you can retrieve tables from header or from a cell
// containing another table (nested tables)
SharedPtr<TableCollection> tables = doc->get_FirstSection()->get_Body()->get_Tables();
// We can make a new array to clone all of the tables in the collection
ASSERT_EQ(2, tables->ToArray()->get_Length());
// Iterate through all tables in the document
for (int i = 0; i < tables->get_Count(); i++)
{
// Get the index of the table node as contained in the parent node of the table
System::Console::WriteLine(String::Format(u"Start of Table {0}",i));
SharedPtr<RowCollection> rows = tables->idx_get(i)->get_Rows();
// RowCollections can be cloned into arrays
ASPOSE_ASSERT_EQ(rows, rows->ToArray());
ASPOSE_ASSERT_NS(rows, rows->ToArray());
// Iterate through all rows in the table
for (int j = 0; j < rows->get_Count(); j++)
{
System::Console::WriteLine(String::Format(u"\tStart of Row {0}",j));
SharedPtr<CellCollection> cells = rows->idx_get(j)->get_Cells();
// RowCollections can also be cloned into arrays
ASPOSE_ASSERT_EQ(cells, cells->ToArray());
ASPOSE_ASSERT_NS(cells, cells->ToArray());
// Iterate through all cells in the row
for (int k = 0; k < cells->get_Count(); k++)
{
// Get the plain text content of this cell
String cellText = cells->idx_get(k)->ToString(Aspose::Words::SaveFormat::Text).Trim();
// Print the content of the cell
System::Console::WriteLine(String::Format(u"\t\tContents of Cell:{0} = \"{1}\"",k,cellText));
}
System::Console::WriteLine(String::Format(u"\tEnd of Row {0}",j));
}
System::Console::WriteLine(String::Format(u"End of Table {0}\n",i));
}

#include <Aspose.Words.Cpp/Model/Tables/Row.h>

+ Inheritance diagram for Aspose::Words::Tables::Row:

Public Member Functions

 Row (SharedPtr< DocumentBase > doc)
 Initializes a new instance of the Row class. More...
 
bool Accept (SharedPtr< DocumentVisitor > visitor) override
 Accepts a visitor. More...
 
void EnsureMinimum ()
 If the Row has no cells, creates and appends one Cell. More...
 
SharedPtr< CellCollectionget_Cells ()
 Provides typed access to the Cell child nodes of the row. More...
 
SharedPtr< Cellget_FirstCell ()
 Returns the first Cell in the row. More...
 
bool get_IsFirstRow ()
 True if this is the first row in a table; false otherwise. More...
 
bool get_IsLastRow ()
 True if this is the last row in a table; false otherwise. More...
 
SharedPtr< Cellget_LastCell ()
 Returns the last Cell in the row. More...
 
NodeType get_NodeType () const override
 Returns NodeType.Row. More...
 
SharedPtr< Tableget_ParentTable ()
 Returns the immediate parent table of the row. More...
 
SharedPtr< RowFormatget_RowFormat ()
 Provides access to the formatting properties of the row. More...
 
String GetText () override
 Gets the text of all cells in this row including the end of row character. More...
 
virtual const TypeInfoGetType () const override
 
virtual bool Is (const TypeInfo &target) const override
 
- Public Member Functions inherited from CompositeNode
SharedPtr< NodeAppendChild (SharedPtr< Node > newChild)
 Adds the specified node to the end of the list of child nodes for this node. More...
 
SharedPtr< NodeCollectionget_ChildNodes ()
 Gets all immediate child nodes of this node. More...
 
SharedPtr< CompositeNodeget_Container () override
 
int32_t get_Count ()
 Gets the number of immediate children of this node. More...
 
SharedPtr< Nodeget_FirstChild () const
 Gets the first child of the node. More...
 
bool get_HasChildNodes ()
 Returns true if this node has any child nodes. More...
 
bool get_IsComposite () override
 Returns true as this node can have child nodes. More...
 
SharedPtr< Nodeget_LastChild () const
 Gets the last child of the node. More...
 
SharedPtr< NodeGetChild (NodeType nodeType, int32_t index, bool isDeep)
 Returns an Nth child node that matches the specified type. More...
 
SharedPtr< NodeCollectionGetChildNodes (NodeType nodeType, bool isDeep)
 Returns a live collection of child nodes that match the specified type. More...
 
SharedPtr< NodeGetCurrentNode () override
 
SharedPtr< IEnumerator< SharedPtr< Node > > > GetEnumerator () override
 Provides support for the for each style iteration over the child nodes of this node. More...
 
SharedPtr< NodeGetNextMatchingNode (SharedPtr< Node > curNode) override
 
int32_t IndexOf (SharedPtr< Node > child)
 Returns the index of the specified child node in the child node array. More...
 
SharedPtr< NodeInsertAfter (SharedPtr< Node > newChild, SharedPtr< Node > refChild)
 Inserts the specified node immediately after the specified reference node. More...
 
SharedPtr< NodeInsertBefore (SharedPtr< Node > newChild, SharedPtr< Node > refChild)
 Inserts the specified node immediately before the specified reference node. More...
 
SharedPtr< NodePrependChild (SharedPtr< Node > newChild)
 Adds the specified node to the beginning of the list of child nodes for this node. More...
 
void RemoveAllChildren ()
 Removes all the child nodes of the current node. More...
 
SharedPtr< NodeRemoveChild (SharedPtr< Node > oldChild)
 Removes the specified child node. More...
 
void RemoveSmartTags ()
 Removes all SmartTag descendant nodes of the current node. More...
 
SharedPtr< NodeListSelectNodes (String xpath)
 Selects a list of nodes matching the XPath expression. More...
 
SharedPtr< NodeSelectSingleNode (String xpath)
 Selects the first Node that matches the XPath expression. More...
 
- Public Member Functions inherited from Node
SharedPtr< NodeClone (bool isCloneChildren)
 Creates a duplicate of the node. More...
 
virtual SharedPtr< DocumentBaseget_Document () const
 Gets the document to which this node belongs. More...
 
SharedPtr< Nodeget_NextSibling ()
 Gets the node immediately following this node. More...
 
SharedPtr< CompositeNodeget_ParentNode ()
 Gets the immediate parent of this node. More...
 
SharedPtr< Nodeget_PreviousSibling ()
 Gets the node immediately preceding this node. More...
 
SharedPtr< Rangeget_Range ()
 Returns a Range object that represents the portion of a document that is contained in this node. More...
 
SharedPtr< CompositeNodeGetAncestor (NodeType ancestorType)
 Gets the first ancestor of the specified NodeType. More...
 
template<typename T >
GetAncestorOf ()
 
SharedPtr< NodeNextPreOrder (SharedPtr< Node > rootNode)
 Gets next node according to the pre-order tree traversal algorithm. More...
 
SharedPtr< NodePreviousPreOrder (SharedPtr< Node > rootNode)
 Gets the previous node according to the pre-order tree traversal algorithm. More...
 
void Remove ()
 Removes itself from the parent. More...
 
String ToString (SaveFormat saveFormat)
 Exports the content of the node into a string in the specified format. More...
 
String ToString (SharedPtr< SaveOptions > saveOptions)
 Exports the content of the node into a string using the specified save options. More...
 
- Public Member Functions inherited from Object
ASPOSECPP_SHARED_API Object ()
 
ASPOSECPP_SHARED_API Object (Object const &x)
 
virtual ASPOSECPP_SHARED_API ~Object ()
 
virtual ASPOSECPP_SHARED_API bool Equals (ptr obj)
 
Detail::SmartPtrCounter * GetCounter ()
 
virtual ASPOSECPP_SHARED_API int GetHashCode () const
 
ASPOSECPP_SHARED_API void Lock ()
 
virtual ASPOSECPP_SHARED_API ptr MemberwiseClone () const
 
Objectoperator= (Object const &x)
 
bool ReferenceEquals (String const &str, std::nullptr_t)
 
bool ReferenceEquals (String const &str1, String const &str2)
 
int RemovedSharedRefs (int count)
 
virtual ASPOSECPP_SHARED_API void SetTemplateWeakPtr (unsigned int argument)
 
int SharedCount () const
 
ObjectSharedRefAdded ()
 
int SharedRefRemovedSafe ()
 
virtual ASPOSECPP_SHARED_API String ToString () const
 
ASPOSECPP_SHARED_API void Unlock ()
 
Detail::SmartPtrCounter * WeakRefAdded ()
 
void WeakRefRemoved ()
 
- Public Member Functions inherited from System::Collections::Generic::IEnumerable< System::SharedPtr< Aspose::Words::Node > >
EnumeratorBasedIterator< T, IEnumerator< T > > begin () noexcept
 
EnumeratorBasedIterator< T, IEnumerator< T > > cbegin () noexcept
 
EnumeratorBasedIterator< T, IEnumerator< T > > cend () noexcept
 
EnumeratorBasedIterator< T, IEnumerator< T > > end () noexcept
 
bool LINQ_All (std::function< bool(T)> predicate)
 
bool LINQ_Any ()
 
bool LINQ_Any (std::function< bool(T)> predicate)
 
SharedPtr< IEnumerable< ResultType > > LINQ_Cast ()
 
SharedPtr< IEnumerable< Result > > LINQ_Cast ()
 
bool LINQ_Contains (T value)
 
int LINQ_Count ()
 
int LINQ_Count (const Func< T, bool > &predicate)
 
LINQ_ElementAt (int index)
 
LINQ_First ()
 
LINQ_First (const Func< T, bool > &predicate)
 
LINQ_FirstOrDefault ()
 
LINQ_FirstOrDefault (std::function< bool(T)> predicate)
 
LINQ_Last ()
 
LINQ_LastOrDefault ()
 
SharedPtr< IEnumerable< ResultType > > LINQ_OfType ()
 
SharedPtr< IEnumerable< Result > > LINQ_OfType ()
 
SharedPtr< IEnumerable< Source > > LINQ_OrderBy (const Func< Source, Key > &keySelector)
 
SharedPtr< IEnumerable< T > > LINQ_OrderBy (const Func< T, Key > &keySelector)
 
SharedPtr< IEnumerable< Result > > LINQ_Select (const Func< Source, Result > &selector)
 
SharedPtr< IEnumerable< ResultType > > LINQ_Select (const Func< T, ResultType > &selector)
 
ArrayPtr< T > LINQ_ToArray ()
 
SharedPtr< List< T > > LINQ_ToList ()
 
SharedPtr< IEnumerable< T > > LINQ_Where (std::function< bool(T)> predicate)
 

Static Public Member Functions

static const TypeInfoType ()
 
- Static Public Member Functions inherited from CompositeNode
static const TypeInfoType ()
 
- Static Public Member Functions inherited from Node
static String NodeTypeToString (NodeType nodeType)
 A utility method that converts a node type enum value into a user friendly string. More...
 
static const TypeInfoType ()
 
- Static Public Member Functions inherited from Object
bool Equals (double const &objA, double const &objB)
 
bool Equals (float const &objA, float const &objB)
 
static std::enable_if<!IsSmartPtr< T1 >::value &&!IsSmartPtr< T2 >::value, bool >::type Equals (T1 const &objA, T2 const &objB)
 
static std::enable_if< IsSmartPtr< T1 >::value &&IsSmartPtr< T2 >::value, bool >::type Equals (T1 const &objA, T2 const &objB)
 
static bool ReferenceEquals (ptr const &objA, ptr const &objB)
 
static std::enable_if<!IsSmartPtr< T >::value, bool >::type ReferenceEquals (T const &objA, std::nullptr_t)
 
static std::enable_if<!IsSmartPtr< T >::value, bool >::type ReferenceEquals (T const &objA, T const &objB)
 
static const TypeInfoType ()
 

Additional Inherited Members

- Public Types inherited from Object
typedef SmartPtr< Objectptr
 
typedef System::Details::SharedMembersType shared_members_type
 
- Public Types inherited from System::Collections::Generic::IEnumerable< System::SharedPtr< Aspose::Words::Node > >
typedef IEnumerator< T > IEnumeratorType
 
typedef T ValueType
 

Constructor & Destructor Documentation

◆ Row()

Aspose::Words::Tables::Row::Row ( System::SharedPtr< Aspose::Words::DocumentBase doc)

Initializes a new instance of the Row class.

When Row is created, it belongs to the specified document, but is not yet part of the document and ParentNode is null.

To append Row to the document use InsertAfter or InsertBefore on the table where you want the row inserted.

Parameters
docThe owner document.

Member Function Documentation

◆ Accept()

bool Aspose::Words::Tables::Row::Accept ( System::SharedPtr< Aspose::Words::DocumentVisitor visitor)
overridevirtual

Accepts a visitor.

Enumerates over this node and all of its children. Each node calls a corresponding method on DocumentVisitor.

For more info see the Visitor design pattern.

Parameters
visitorThe visitor that will visit the nodes.
Returns
True if all nodes were visited; false if DocumentVisitor stopped the operation before visiting all nodes.

Implements Aspose::Words::Node.

◆ EnsureMinimum()

void Aspose::Words::Tables::Row::EnsureMinimum ( )

If the Row has no cells, creates and appends one Cell.

Examples

Shows how to ensure a row node is valid.

auto doc = MakeObject<Document>();
// Create a new table and add it to the document
auto table = MakeObject<Table>(doc);
doc->get_FirstSection()->get_Body()->AppendChild(table);
// Create a new row and add it to the table
auto row = MakeObject<Row>(doc);
table->AppendChild(row);
// Currently, the row does not contain any cells or nodes that can have content added to them
ASSERT_EQ(0, row->GetChildNodes(Aspose::Words::NodeType::Any, true)->get_Count());
// Ensure the row has at least one cell with one paragraph that we can edit
row->EnsureMinimum();
row->get_FirstCell()->get_FirstParagraph()->AppendChild(MakeObject<Run>(doc, u"Hello world!"));

◆ get_Cells()

System::SharedPtr<Aspose::Words::Tables::CellCollection> Aspose::Words::Tables::Row::get_Cells ( )

Provides typed access to the Cell child nodes of the row.

Examples

Shows how to iterate through all tables in the document and display the content from each cell.

auto doc = MakeObject<Document>(MyDir + u"Tables.docx");
// Here we get all tables from the Document node. You can do this for any other composite node
// which can contain block level nodes. For example you can retrieve tables from header or from a cell
// containing another table (nested tables)
SharedPtr<TableCollection> tables = doc->get_FirstSection()->get_Body()->get_Tables();
// We can make a new array to clone all of the tables in the collection
ASSERT_EQ(2, tables->ToArray()->get_Length());
// Iterate through all tables in the document
for (int i = 0; i < tables->get_Count(); i++)
{
// Get the index of the table node as contained in the parent node of the table
System::Console::WriteLine(String::Format(u"Start of Table {0}",i));
SharedPtr<RowCollection> rows = tables->idx_get(i)->get_Rows();
// RowCollections can be cloned into arrays
ASPOSE_ASSERT_EQ(rows, rows->ToArray());
ASPOSE_ASSERT_NS(rows, rows->ToArray());
// Iterate through all rows in the table
for (int j = 0; j < rows->get_Count(); j++)
{
System::Console::WriteLine(String::Format(u"\tStart of Row {0}",j));
SharedPtr<CellCollection> cells = rows->idx_get(j)->get_Cells();
// RowCollections can also be cloned into arrays
ASPOSE_ASSERT_EQ(cells, cells->ToArray());
ASPOSE_ASSERT_NS(cells, cells->ToArray());
// Iterate through all cells in the row
for (int k = 0; k < cells->get_Count(); k++)
{
// Get the plain text content of this cell
String cellText = cells->idx_get(k)->ToString(Aspose::Words::SaveFormat::Text).Trim();
// Print the content of the cell
System::Console::WriteLine(String::Format(u"\t\tContents of Cell:{0} = \"{1}\"",k,cellText));
}
System::Console::WriteLine(String::Format(u"\tEnd of Row {0}",j));
}
System::Console::WriteLine(String::Format(u"End of Table {0}\n",i));
}

◆ get_FirstCell()

System::SharedPtr<Aspose::Words::Tables::Cell> Aspose::Words::Tables::Row::get_FirstCell ( )

Returns the first Cell in the row.

◆ get_IsFirstRow()

bool Aspose::Words::Tables::Row::get_IsFirstRow ( )

True if this is the first row in a table; false otherwise.

◆ get_IsLastRow()

bool Aspose::Words::Tables::Row::get_IsLastRow ( )

True if this is the last row in a table; false otherwise.

Examples

Shows how to set a table to stay together on the same page.

auto doc = MakeObject<Document>(MyDir + u"Table spanning two pages.docx");
auto table = System::DynamicCast<Aspose::Words::Tables::Table>(doc->GetChild(Aspose::Words::NodeType::Table, 0, true));
// Enabling KeepWithNext for every paragraph in the table except for the last ones in the last row
// will prevent the table from being split across pages
for (auto cell : System::IterateOver(table->GetChildNodes(Aspose::Words::NodeType::Cell, true)->LINQ_OfType<SharedPtr<Cell> >()))
{
for (auto para : System::IterateOver(cell->get_Paragraphs()->LINQ_OfType<SharedPtr<Paragraph> >()))
{
ASSERT_TRUE(para->get_IsInCell());
if (!(cell->get_ParentRow()->get_IsLastRow() && para->get_IsEndOfCell()))
{
para->get_ParagraphFormat()->set_KeepWithNext(true);
}
}
}
doc->Save(ArtifactsDir + u"Table.KeepTableTogether.docx");

◆ get_LastCell()

System::SharedPtr<Aspose::Words::Tables::Cell> Aspose::Words::Tables::Row::get_LastCell ( )

Returns the last Cell in the row.

◆ get_NodeType()

Aspose::Words::NodeType Aspose::Words::Tables::Row::get_NodeType ( ) const
overridevirtual

Returns NodeType.Row.

Implements Aspose::Words::Node.

◆ get_ParentTable()

System::SharedPtr<Aspose::Words::Tables::Table> Aspose::Words::Tables::Row::get_ParentTable ( )

Returns the immediate parent table of the row.

◆ get_RowFormat()

System::SharedPtr<Aspose::Words::Tables::RowFormat> Aspose::Words::Tables::Row::get_RowFormat ( )

Provides access to the formatting properties of the row.

Examples

Shows how to modify the format of rows and cells.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
SharedPtr<Table> table = builder->StartTable();
builder->InsertCell();
builder->Write(u"City");
builder->InsertCell();
builder->Write(u"Country");
builder->EndRow();
builder->InsertCell();
builder->Write(u"London");
builder->InsertCell();
builder->Write(u"U.K.");
builder->EndTable();
// The appearance of rows and individual cells can be edited using the respective formatting objects
SharedPtr<Aspose::Words::Tables::RowFormat> rowFormat = table->get_FirstRow()->get_RowFormat();
rowFormat->set_Height(25);
rowFormat->get_Borders()->idx_get(Aspose::Words::BorderType::Bottom)->set_Color(System::Drawing::Color::get_Red());
SharedPtr<Aspose::Words::Tables::CellFormat> cellFormat = table->get_LastRow()->get_FirstCell()->get_CellFormat();
cellFormat->set_Width(100);
cellFormat->get_Shading()->set_BackgroundPatternColor(System::Drawing::Color::get_Orange());
doc->Save(ArtifactsDir + u"Table.RowCellFormat.docx");

Shows how to modify formatting of a table row.

auto doc = MakeObject<Document>(MyDir + u"Tables.docx");
auto table = System::DynamicCast<Aspose::Words::Tables::Table>(doc->GetChild(Aspose::Words::NodeType::Table, 0, true));
// Retrieve the first row in the table
SharedPtr<Row> firstRow = table->get_FirstRow();
// Modify some row level properties
firstRow->get_RowFormat()->get_Borders()->set_LineStyle(Aspose::Words::LineStyle::None);
firstRow->get_RowFormat()->set_HeightRule(Aspose::Words::HeightRule::Auto);
firstRow->get_RowFormat()->set_AllowBreakAcrossPages(true);
doc->Save(ArtifactsDir + u"Table.RowFormat.docx");

◆ GetText()

System::String Aspose::Words::Tables::Row::GetText ( )
overridevirtual

Gets the text of all cells in this row including the end of row character.

Returns concatenated text of all child nodes with the end of row character ControlChar.Cell appended at the end.

The returned string includes all control and special characters as described in ControlChar.

Reimplemented from Aspose::Words::CompositeNode.

◆ GetType()

virtual const System::TypeInfo& Aspose::Words::Tables::Row::GetType ( ) const
overridevirtual

Reimplemented from Aspose::Words::CompositeNode.

◆ Is()

virtual bool Aspose::Words::Tables::Row::Is ( const System::TypeInfo target) const
overridevirtual

Reimplemented from Aspose::Words::CompositeNode.

◆ Type()

static const System::TypeInfo& Aspose::Words::Tables::Row::Type ( )
static
String
@ Bottom
Specifies the bottom border of a paragraph or a table cell.
@ Text
Saves the document in the plain text format.
static ASPOSECPP_SHARED_API void WriteLine()
std::enable_if_t<!Details::IsIterable< Enumerable >::value, Details::EnumeratorAdapter< Enumerable, T > > IterateOver(System::SmartPtr< Enumerable > enumerable)
@ None
static ASPOSECPP_SHARED_API Color get_Orange()
@ Auto
The height will grow automatically to accommodate all text inside an object.
static ASPOSECPP_SHARED_API Color get_Red()
@ Table
A Table object that represents a table in a Word document. A Table node can have Row nodes.
@ Any
Indicates all node types. Allows to select all children.
@ Cell
A cell of a table row. A Cell node can have Paragraph and Table nodes.