Aspose::Words::Tables::RowCollection::ToArray method
Contents
[
Hide
]RowCollection::ToArray method
Copies all rows from the collection to a new array of rows.
System::ArrayPtr<System::SharedPtr<Aspose::Words::Tables::Row>> Aspose::Words::Tables::RowCollection::ToArray()
ReturnValue
An array of rows.
Examples
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
- Class RowCollection
- Namespace Aspose::Words::Tables
- Library Aspose.Words for C++