FieldStyleRef
Contents
[
Hide
]FieldStyleRef class
Implements the STYLEREF field.
To learn more, visit the Working with Fields documentation article.
public class FieldStyleRef : Field
Constructors
Name | Description |
---|---|
FieldStyleRef() | The default constructor. |
Properties
Name | Description |
---|---|
DisplayResult { get; } | Gets the text that represents the displayed field result. |
End { get; } | Gets the node that represents the field end. |
Format { get; } | Gets a FieldFormat object that provides typed access to field’s formatting. |
InsertParagraphNumber { get; set; } | Gets or sets whether to insert the paragraph number of the referenced paragraph exactly as it appears in the document. |
InsertParagraphNumberInFullContext { get; set; } | Gets or sets whether to insert the paragraph number of the referenced paragraph in full context. |
InsertParagraphNumberInRelativeContext { get; set; } | Gets or sets whether to insert the paragraph number of the referenced paragraph in relative context. |
InsertRelativePosition { get; set; } | Gets or sets whether to insert the relative position of the referenced paragraph. |
IsDirty { get; set; } | Gets or sets whether the current result of the field is no longer correct (stale) due to other modifications made to the document. |
IsLocked { get; set; } | Gets or sets whether the field is locked (should not recalculate its result). |
LocaleId { get; set; } | Gets or sets the LCID of the field. |
Result { get; set; } | Gets or sets text that is between the field separator and field end. |
SearchFromBottom { get; set; } | Gets or sets whether to search from the bottom of the current page, rather from the top. |
Separator { get; } | Gets the node that represents the field separator. Can be null . |
Start { get; } | Gets the node that represents the start of the field. |
StyleName { get; set; } | Gets or sets the name of the style by which the text to search for is formatted. |
SuppressNonDelimiters { get; set; } | Gets or sets whether to suppress non-delimiter characters. |
virtual Type { get; } | Gets the Microsoft Word field type. |
Methods
Name | Description |
---|---|
GetFieldCode() | 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. |
GetFieldCode(bool) | Returns text between field start and field separator (or field end if there is no separator). |
Remove() | 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 . |
Unlink() | Performs the field unlink. |
Update() | Performs the field update. Throws if the field is being updated already. |
Update(bool) | Performs a field update. Throws if the field is being updated already. |
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 using a Microsoft Word list template.
Aspose.Words.Lists.List list = doc.Lists.Add(Aspose.Words.Lists.ListTemplate.NumberDefault);
// This generated list will display "1.a )".
// Space before the bracket is a non-delimiter character, which we can suppress.
list.ListLevels[0].NumberFormat = "\x0000.";
list.ListLevels[1].NumberFormat = "\x0001 )";
// Add text and apply paragraph styles that STYLEREF fields will reference.
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 display the first "List Paragraph"-styled text in the document.
builder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary);
FieldStyleRef field = (FieldStyleRef)builder.InsertField(FieldType.FieldStyleRef, true);
field.StyleName = "List Paragraph";
// Place a STYLEREF field in the footer, and have it display the last text.
builder.MoveToHeaderFooter(HeaderFooterType.FooterPrimary);
field = (FieldStyleRef)builder.InsertField(FieldType.FieldStyleRef, true);
field.StyleName = "List Paragraph";
field.SearchFromBottom = true;
builder.MoveToDocumentEnd();
// We can also use STYLEREF fields to reference the list numbers of lists.
builder.Write("\nParagraph number: ");
field = (FieldStyleRef)builder.InsertField(FieldType.FieldStyleRef, true);
field.StyleName = "Quote";
field.InsertParagraphNumber = true;
builder.Write("\nParagraph number, relative context: ");
field = (FieldStyleRef)builder.InsertField(FieldType.FieldStyleRef, true);
field.StyleName = "Quote";
field.InsertParagraphNumberInRelativeContext = true;
builder.Write("\nParagraph number, full context: ");
field = (FieldStyleRef)builder.InsertField(FieldType.FieldStyleRef, true);
field.StyleName = "Quote";
field.InsertParagraphNumberInFullContext = true;
builder.Write("\nParagraph number, full context, non-delimiter chars suppressed: ");
field = (FieldStyleRef)builder.InsertField(FieldType.FieldStyleRef, true);
field.StyleName = "Quote";
field.InsertParagraphNumberInFullContext = true;
field.SuppressNonDelimiters = true;
doc.UpdatePageLayout();
doc.UpdateFields();
doc.Save(ArtifactsDir + "Field.STYLEREF.docx");
See Also
- class Field
- namespace Aspose.Words.Fields
- assembly Aspose.Words