AddNumberedCrossRef

function AddNumberedCrossRef(
  sRefType: numberedRefTo = null,
  oParaTo: ApiParagraph = null,
  bLink: boolean = true,
  bAboveBelow: boolean = false,
  sSepWith: string = "",
): boolean

Description

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

Parameters

sRefTypenumberedRefTodefault: null

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

oParaToApiParagraphdefault: null

The numbered 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).

sSepWithstringdefault: ""

A number separator (used only with the "fullCtxParaNum" sRefType).

Returns

boolean

Try It

var oDocument = Api.GetDocument();
var oNumbering = oDocument.CreateNumbering("numbered");
for (let nLvl = 0; nLvl < 8; ++nLvl) {
   var oNumLvl = oNumbering.GetLevel(nLvl);
   var sFormatString = "";
   for (let nTempLvl = 0; nTempLvl <= nLvl; ++nTempLvl) sFormatString += "%" + nTempLvl + ".";
   oNumLvl.SetCustomType("lowerRoman", sFormatString, "left");
   oNumLvl.SetStart(nLvl + 1);
   oNumLvl.SetSuff("space");
   var oParagraph = Api.CreateParagraph();
   oParagraph.AddText("Custom numbered lvl " + (nLvl + 1));
   oParagraph.SetNumbering(oNumLvl);
   oParagraph.SetContextualSpacing(true);
   oDocument.Push(oParagraph);
}
var aNumberedParagraphs = oDocument.GetAllNumberedParagraphs();
oParagraph = Api.CreateParagraph();
oParagraph.AddText("An example of the customized numbering type can be found in the paragraph № ");
oDocument.Push(oParagraph);
oParagraph.AddNumberedCrossRef("paraNum", aNumberedParagraphs[1], true, true);

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).