Aspose::Words::Tables::CellCollection class

CellCollection class

Provides typed access to a collection of Cell nodes. To learn more, visit the Working with Tables documentation article.

class CellCollection : public Aspose::Words::NodeCollection

Methods

MethodDescription
Add(const System::SharedPtr<Aspose::Words::Node>&)Adds a node to the end of the collection.
Clear()Removes all nodes from this collection and from the document.
Contains(const System::SharedPtr<Aspose::Words::Node>&)Determines whether a node is in the collection.
get_Count()Gets the number of nodes in the collection.
GetEnumerator() overrideProvides a simple “foreach” style iteration over the collection of nodes.
GetType() const override
idx_get(int32_t)Retrieves a Cell at the given index.
IndexOf(const System::SharedPtr<Aspose::Words::Node>&)Returns the zero-based index of the specified node.
Insert(int32_t, const System::SharedPtr<Aspose::Words::Node>&)Inserts a node into the collection at the specified index.
Is(const System::TypeInfo&) const override
Remove(const System::SharedPtr<Aspose::Words::Node>&)Removes the node from the collection and from the document.
RemoveAt(int32_t)Removes the node at the specified index from the collection and from the document.
ToArray()Copies all cells from the collection to a new array of cells.
static Type()

Examples

Shows how to iterate through all tables in the document and print the contents of each cell.

auto doc = MakeObject<Document>(MyDir + u"Tables.docx");
SharedPtr<TableCollection> tables = doc->get_FirstSection()->get_Body()->get_Tables();

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

for (int i = 0; i < tables->get_Count(); i++)
{
    std::cout << "Start of Table " << i << std::endl;

    SharedPtr<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 (int j = 0; j < rows->get_Count(); j++)
    {
        std::cout << "\tStart of Row " << j << std::endl;

        SharedPtr<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 (int k = 0; k < cells->get_Count(); k++)
        {
            String cellText = cells->idx_get(k)->ToString(SaveFormat::Text).Trim();
            std::cout << "\t\tContents of Cell:" << k << " = \"" << cellText << "\"" << std::endl;
        }

        std::cout << "\tEnd of Row " << j << std::endl;
    }

    std::cout << "End of Table " << i << "\n" << std::endl;
}

See Also