AddCaption(sAdditional, [sLabel], [bExludeLabel], [sNumberingFormat], [bBefore], [nHeadingLvl], [sCaptionSep]) → { boolean }

Adds a caption paragraph after (or before) the current content control. Please note that the current content control must be in the document (not in the footer/header). And if the current content control is placed in a shape, then a caption is added after (or before) the parent shape.


Name Type Default Description
sAdditional string

The additional text.

sLabel CaptionLabel | String "Table"

The caption label.

bExludeLabel boolean false

Specifies whether to exclude the label from the caption.

sNumberingFormat CaptionNumberingFormat "Arabic"

The possible caption numbering format.

bBefore boolean false

Specifies whether to insert the caption before the current content control (true) or after (false) (after/before the shape if it is placed in the shape).

nHeadingLvl Number null

The heading level (used if you want to specify the chapter number). If you want to specify "Heading 1", then nHeadingLvl === 0 and etc.

sCaptionSep CaptionSep "hyphen"

The caption separator (used if you want to specify the chapter number).




Copy code
var oDocument = Api.GetDocument();
var oBlockLvlSdt = Api.CreateBlockLvlSdt();
var oParagraph = Api.CreateParagraph();
var oDrawing = Api.CreateImage("", 60 * 36000, 35 * 36000);
oBlockLvlSdt.AddElement(oParagraph, 0);
oDocument.AddElement(0, oBlockLvlSdt);
oBlockLvlSdt.AddCaption("", "Figure", false, "Arabic", false, undefined, "hyphen");
builder.SaveFile("docx", "AddCaption.docx");

Resulting document