Get Started
Usage API
More information

InsertParagraph

InsertParagraph(paragraph, sPosition, beRNewPara) → { ApiParagraph | null }

Inserts a paragraph at the specified position.

Parameters:

Name Type Description
paragraph string | ApiParagraph

Text or paragraph.

sPosition string

The position where the text or paragraph will be inserted ("before" or "after" the paragraph specified).

beRNewPara bool

Defines if this method returns a new paragraph (true) or the current paragraph (false).

Returns:

Type
ApiParagraph | null

Example

Copy code
builder.CreateFile("docx");
var oDocument = Api.GetDocument();
var oParagraph1 = oDocument.GetElement(0);
oParagraph1.AddText("This is just a sample text.");
var oParagraph2 = Api.CreateParagraph();
oParagraph2.AddText("This paragraph was inserted here.");
oParagraph1.InsertParagraph(oParagraph2, "after", true);
builder.SaveFile("docx", "InsertParagraph.docx");
builder.CloseFile();

Resulting document