Get Started
Usage API
More information

AddCaptionCrossRef

AddCaptionCrossRef(sCaption, sRefType, oParaTo, [bLink], [bAboveBelow]) → { boolean }

Adds a caption cross-reference to the current paragraph. The paragraph must be in the document.

Parameters:

Name Type Default Description
sCaption CaptionLabel | string

The caption label ("Equation", "Figure", "Table" or another caption label).

sRefType captionRefTo

The text or numeric value of a caption reference you want to insert.

oParaTo ApiParagraph

The caption paragraph to be referred to (must be in the document).

bLink boolean true

Specifies if the reference will be inserted as a hyperlink.

bAboveBelow boolean false

Specifies if the above/below words indicating the position of the reference should be included (used only with the "pageNum" sRefType).

Returns:

Type
boolean

Example

Copy code
builder.CreateFile("docx");
var oDocument = Api.GetDocument();
var oElement = oDocument.GetElement(0);
var nElementCount = oElement.GetElementsCount();
if (nElementCount == 1) {
    var oRun = Api.CreateRun();
    oRun.AddText("Add a caption to the table. To do this, select the table below, open the References tab, click Caption, change caption parameters in the opened window if you want and click OK. After that, copy the macro above (without the first and last two lines) and run it (Plugins -> Macros).");
    oElement.AddElement(oRun);
    var oTable = Api.CreateTable(3, 3);
    var oTableStyle = oDocument.CreateStyle("CustomTableStyle", "table");
    oTableStyle.SetBasedOn(oDocument.GetStyle("Bordered - Accent 5"));
    oTable.SetStyle(oTableStyle);
    oTable.SetWidth("percent", 100);
    oDocument.Push(oTable);
}
else {
    var aCaptionParagraphs = oDocument.GetAllCaptionParagraphs("table");
    var oParagraph = Api.CreateParagraph();
    oParagraph.AddText("Complete ");
    oDocument.Push(oParagraph);
    oParagraph.AddCaptionCrossRef("table", "labelNumber", aCaptionParagraphs[0]);
}
builder.SaveFile("docx", "AddCaptionCrossRef.docx");
builder.CloseFile();

Resulting document