CellCollection class

CellCollection class

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

Inheritance: CellCollectionNodeCollection

Properties

NameDescription
countGets the number of nodes in the collection.
(Inherited from NodeCollection)
this[]
(Inherited from NodeCollection)

Methods

NameDescription
add(node)Adds a node to the end of the collection.
(Inherited from NodeCollection)
clear()Removes all nodes from this collection and from the document.
(Inherited from NodeCollection)
contains(node)Determines whether a node is in the collection.
(Inherited from NodeCollection)
indexOf(node)Returns the zero-based index of the specified node.
(Inherited from NodeCollection)
insert(index, node)Inserts a node into the collection at the specified index.
(Inherited from NodeCollection)
remove(node)Removes the node from the collection and from the document.
(Inherited from NodeCollection)
removeAt(index)Removes the node at the specified index from the collection and from the document.
(Inherited from NodeCollection)
toArray()Copies all cells from the collection to a new array of cells.

Examples

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

let doc = new aw.Document(base.myDir + "Tables.docx");
let tables = doc.firstSection.body.tables;

expect(tables.toArray().length).toEqual(2);

for (let i = 0; i < tables.count; i++)
{
  console.log(`Start of Table ${i}`);

  let rows = tables.at(i).rows;

  for (let j = 0; j < rows.count; j++)
  {
    console.log(`\tStart of Row ${j}`);

    let cells = rows.at(j).cells;

    for (let k = 0; k < cells.count; k++)
    {
      let cellText = cells.at(k).toString(aw.SaveFormat.Text).trim();
      console.log(`\t\tContents of Cell:${k} = \"${cellText}\"`);
    }

    console.log(`\tEnd of Row ${j}`);
  }

  console.log(`End of Table ${i}\n`);
}

See Also