AddHeadingCrossRef

function AddHeadingCrossRef(
  sRefType: headingRefTo = null,
  oParaTo: ApiParagraph = null,
  bLink: boolean = true,
  bAboveBelow: boolean = false,
): boolean

Description

Adds a heading cross-reference to the current paragraph. Please note that this paragraph must be in the document.

Parameters

sRefTypeheadingRefTodefault: null

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

oParaToApiParagraphdefault: null

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

bLinkbooleandefault: true

Specifies if the reference will be inserted as a hyperlink.

bAboveBelowbooleandefault: false

Specifies if the above/below words indicating the position of the reference should be included (don't used with the "text" and "aboveBelow" sRefType).

Returns

boolean

Try It

var oDocument = Api.GetDocument();
var oNewDocumentStyle = oDocument.GetStyle("Heading 1");
var oParagraph = oDocument.GetElement(0);
oParagraph.SetStyle(oNewDocumentStyle);
oParagraph.AddText("Cross-reference method");
var aHeadingParagraphs = oDocument.GetAllHeadingParagraphs();
oParagraph = Api.CreateParagraph();
oParagraph.AddText("Heading 1 style is applied to the heading ");
oDocument.Push(oParagraph);
oParagraph.AddHeadingCrossRef("text", aHeadingParagraphs[0]);

Get Help

  • If you have any questions about ONLYOFFICE Docs, try the FAQ section first.
  • You can request a feature or report a bug by posting an issue on GitHub.
  • You can also ask our developers on ONLYOFFICE forum (registration required).