FieldStyleRef Class

Implements the STYLEREF field.
Inheritance Hierarchy

Namespace:  Aspose.Words.Fields
Assembly:  Aspose.Words (in Aspose.Words.dll) Version: 20.3
Syntax
public class FieldStyleRef : Field

The FieldStyleRef type exposes the following members.

Constructors
  NameDescription
Public methodFieldStyleRef
Initializes a new instance of the FieldStyleRef class
Properties
  NameDescription
Public propertyCode exampleDisplayResult
Gets the text that represents the displayed field result.
(Inherited from Field.)
Public propertyCode exampleEnd
Gets the node that represents the field end.
(Inherited from Field.)
Public propertyCode exampleFormat
Gets a FieldFormat object that provides typed access to field's formatting.
(Inherited from Field.)
Public propertyCode exampleInsertParagraphNumber
Gets or sets whether to insert the paragraph number of the referenced paragraph exactly as it appears in the document.
Public propertyCode exampleInsertParagraphNumberInFullContext
Gets or sets whether to insert the paragraph number of the referenced paragraph in full context.
Public propertyCode exampleInsertParagraphNumberInRelativeContext
Gets or sets whether to insert the paragraph number of the referenced paragraph in relative context.
Public propertyCode exampleInsertRelativePosition
Gets or sets whether to insert the relative position of the referenced paragraph.
Public propertyCode exampleIsDirty
Gets or sets whether the current result of the field is no longer correct (stale) due to other modifications made to the document.
(Inherited from Field.)
Public propertyCode exampleIsLocked
Gets or sets whether the field is locked (should not recalculate its result).
(Inherited from Field.)
Public propertyCode exampleLocaleId
Gets or sets the LCID of the field.
(Inherited from Field.)
Public propertyCode exampleResult
Gets or sets text that is between the field separator and field end.
(Inherited from Field.)
Public propertyCode exampleSearchFromBottom
Gets or sets whether to search from the bottom of the current page, rather from the top.
Public propertyCode exampleSeparator
Gets the node that represents the field separator. Can be null.
(Inherited from Field.)
Public propertyCode exampleStart
Gets the node that represents the start of the field.
(Inherited from Field.)
Public propertyCode exampleStyleName
Gets or sets the name of the style by which the text to search for is formatted.
Public propertyCode exampleSuppressNonDelimiters
Gets or sets whether to suppress non-delimiter characters.
Public propertyCode exampleType
Gets the Microsoft Word field type.
(Inherited from Field.)
Methods
  NameDescription
Public methodEquals (Inherited from Object.)
Public methodCode exampleGetFieldCode
Returns text between field start and field separator (or field end if there is no separator). Both field code and field result of child fields are included.
(Inherited from Field.)
Public methodCode exampleGetFieldCode(Boolean)
Returns text between field start and field separator (or field end if there is no separator).
(Inherited from Field.)
Public methodGetHashCode (Inherited from Object.)
Public methodGetType (Inherited from Object.)
Public methodCode exampleRemove
Removes the field from the document. Returns a node right after the field. If the field's end is the last child of its parent node, returns its parent paragraph. If the field is already removed, returns null.
(Inherited from Field.)
Public methodToString (Inherited from Object.)
Public methodCode exampleUnlink
Performs the field unlink.
(Inherited from Field.)
Public methodCode exampleUpdate
Performs the field update. Throws if the field is being updated already.
(Inherited from Field.)
Public methodCode exampleUpdate(Boolean)
Performs a field update. Throws if the field is being updated already.
(Inherited from Field.)
Remarks
The STYLEREF is used to reference a fragment of text within the document that is formatted with the specified style.
Examples
Shows how to use STYLEREF fields.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Create a list based on one of the Microsoft Word list templates
Aspose.Words.Lists.List list = doc.Lists.Add(Aspose.Words.Lists.ListTemplate.NumberDefault);

// This generated list will look like "1.a )"
// The space before the bracket is a non-delimiter character that can be suppressed
list.ListLevels[0].NumberFormat = "\x0000.";
list.ListLevels[1].NumberFormat = "\x0001 )";

// Add text and apply paragraph styles that will be referenced by STYLEREF fields
builder.ListFormat.List = list;
builder.ListFormat.ListIndent();
builder.ParagraphFormat.Style = doc.Styles["List Paragraph"];
builder.Writeln("Item 1");
builder.ParagraphFormat.Style = doc.Styles["Quote"];
builder.Writeln("Item 2");
builder.ParagraphFormat.Style = doc.Styles["List Paragraph"];
builder.Writeln("Item 3");
builder.ListFormat.RemoveNumbers();
builder.ParagraphFormat.Style = doc.Styles["Normal"];

// Place a STYLEREF field in the header and have it display the first "List Paragraph"-styled text in the document
builder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary);
FieldStyleRef fieldStyleRef = (FieldStyleRef)builder.InsertField(FieldType.FieldStyleRef, true);
fieldStyleRef.StyleName = "List Paragraph";

// Place a STYLEREF field in the footer and have it display the last text
builder.MoveToHeaderFooter(HeaderFooterType.FooterPrimary);
fieldStyleRef = (FieldStyleRef)builder.InsertField(FieldType.FieldStyleRef, true);
fieldStyleRef.StyleName = "List Paragraph";
fieldStyleRef.SearchFromBottom = true;

builder.MoveToDocumentEnd();

// We can also use STYLEREF fields to reference the list numbers of lists
builder.Write("\nParagraph number: ");
fieldStyleRef = (FieldStyleRef)builder.InsertField(FieldType.FieldStyleRef, true);
fieldStyleRef.StyleName = "Quote";
fieldStyleRef.InsertParagraphNumber = true;

builder.Write("\nParagraph number, relative context: ");
fieldStyleRef = (FieldStyleRef)builder.InsertField(FieldType.FieldStyleRef, true);
fieldStyleRef.StyleName = "Quote";
fieldStyleRef.InsertParagraphNumberInRelativeContext = true;

builder.Write("\nParagraph number, full context: ");
fieldStyleRef = (FieldStyleRef)builder.InsertField(FieldType.FieldStyleRef, true);
fieldStyleRef.StyleName = "Quote";
fieldStyleRef.InsertParagraphNumberInFullContext = true;

builder.Write("\nParagraph number, full context, non-delimiter chars suppressed: ");
fieldStyleRef = (FieldStyleRef)builder.InsertField(FieldType.FieldStyleRef, true);
fieldStyleRef.StyleName = "Quote";
fieldStyleRef.InsertParagraphNumberInFullContext = true;
fieldStyleRef.SuppressNonDelimiters = true;

doc.UpdateFields();
doc.Save(ArtifactsDir + "Field.STYLEREF.docx");
See Also