firstParagraph property

Cell.firstParagraph property

Gets the first paragraph among the immediate children.

get firstParagraph(): Aspose.Words.Paragraph

Examples

Shows how to build a nested table without using a document builder.

test('CreateNestedTable', () => {
  let doc = new aw.Document();

  // Create the outer table with three rows and four columns, and then add it to the document.
  let outerTable = createTable(doc, 3, 4, "Outer Table");
  doc.firstSection.body.appendChild(outerTable);

  // Create another table with two rows and two columns and then insert it into the first table's first cell.
  let innerTable = createTable(doc, 2, 2, "Inner Table");
  outerTable.firstRow.firstCell.appendChild(innerTable);

  doc.save(base.artifactsDir + "Table.CreateNestedTable.docx");
});


/// <summary>
/// Creates a new table in the document with the given dimensions and text in each cell.
/// </summary>
function createTable(doc, rowCount, cellCount, cellText)
{
  let table = new aw.Tables.Table(doc);

  for (let rowId = 1; rowId <= rowCount; rowId++)
  {
    let row = new aw.Tables.Row(doc);
    table.appendChild(row);

    for (let cellId = 1; cellId <= cellCount; cellId++)
    {
      let cell = new aw.Tables.Cell(doc);
      cell.appendChild(new aw.Paragraph(doc));
      cell.firstParagraph.appendChild(new aw.Run(doc, cellText));

      row.appendChild(cell);
    }
  }

  // You can use the "Title" and "Description" properties to add a title and description respectively to your table.
  // The table must have at least one row before we can use these properties.
  // These properties are meaningful for ISO / IEC 29500 compliant .docx documents (see the OoxmlCompliance class).
  // If we save the document to pre-ISO/IEC 29500 formats, Microsoft Word ignores these properties.
  table.title = "Aspose table title";
  table.description = "Aspose table description";

  return table;
}

Shows how to create a nested table using a document builder.

let doc = new aw.Document();
let builder = new aw.DocumentBuilder(doc);

// Build the outer table.
let cell = builder.insertCell();
builder.writeln("Outer Table Cell 1");
builder.insertCell();
builder.writeln("Outer Table Cell 2");
builder.endTable();

// Move to the first cell of the outer table, the build another table inside the cell.
builder.moveTo(cell.firstParagraph);
builder.insertCell();
builder.writeln("Inner Table Cell 1");
builder.insertCell();
builder.writeln("Inner Table Cell 2");
builder.endTable();

doc.save(base.artifactsDir + "DocumentBuilder.InsertNestedTable.docx");

See Also