Method InsertCrossReference
InsertCrossReference(WordDocument, DocumentPosition, CrossReferenceTarget, CrossReferenceKind, bool, FieldUpdateOptions?)
Inserts a cross-reference at a position, as one undoable edit: a REF, PAGEREF or NOTEREF field with its result,
\h when it links, after putting Word's _Ref bookmark round a heading's text or a note's mark (one
already there is reused).
public static DocumentEdit InsertCrossReference(this WordDocument document, DocumentPosition at, CrossReferenceTarget target, CrossReferenceKind kind, bool hyperlink = true, FieldUpdateOptions? options = null)
Parameters
documentWordDocumentThe document.
atDocumentPositionWhere the reference goes.
targetCrossReferenceTargetThe heading, bookmark or note.
kindCrossReferenceKindWhat it shows: text and above/below for a heading or bookmark, a number for a note, a page for any.
hyperlinkboolWhether a click on it goes to the target (
\h). Defaults to true, as Word's dialog.optionsFieldUpdateOptionsWhat PAGEREF shows (PageReference), or null to leave it to layout.
Returns
- DocumentEdit
The edit; After is just past the reference.
Exceptions
- ArgumentNullException
documentortargetis null.- ArgumentException
The position or the target is not in the document, the bookmark does not exist, the heading has no text, or the kind does not fit the target.
- InvalidOperationException
The position is in a shape's text box or inside synthesized content.