clone method

clone()

Creates a duplicate of this section.

clone()

Examples

Shows how to add and remove sections in a document.

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

builder.write("Section 1");
builder.insertBreak(aw.BreakType.SectionBreakNewPage);
builder.write("Section 2");

expect(doc.getText().trim()).toEqual("Section 1\u000cSection 2");

// Delete the first section from the document.
doc.sections.removeAt(0);

expect(doc.getText().trim()).toEqual("Section 2");

// Append a copy of what is now the first section to the end of the document.
let lastSectionIdx = doc.sections.count - 1;
let newSection = doc.sections.at(lastSectionIdx).clone();
doc.sections.add(newSection);

expect(doc.getText().trim()).toEqual("Section 2\u000cSection 2");

See Also