FieldXE Class

Implements the XE field.

Inheritance Hierarchy

Namespace:  Aspose.Words.Fields
Assembly:  Aspose.Words (in Aspose.Words.dll) Version: 20.8.0

Syntax

public class FieldXE : Field

The FieldXE type exposes the following members.

Constructors

  NameDescription
Public methodFieldXE
Initializes a new instance of the FieldXE 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 exampleEntryType
Gets or sets an index entry type.
Public propertyCode exampleFormat
Gets a FieldFormat object that provides typed access to field's formatting.
(Inherited from Field.)
Public propertyCode exampleHasPageRangeBookmarkName
Gets a value indicating whether a page range bookmark name is provided through the field's code.
Public propertyCode exampleIsBold
Gets or sets whether to apply bold formatting to the entry's page number.
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 exampleIsItalic
Gets or sets whether to apply italic formatting to the entry's page number.
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 examplePageNumberReplacement
Gets or sets text used in place of a page number.
Public propertyCode examplePageRangeBookmarkName
Gets or sets the name of the bookmark that marks a range of pages that is inserted as the entry's page number.
Public propertyCode exampleResult
Gets or sets text that is between the field separator and field end.
(Inherited from Field.)
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 exampleText
Gets or sets the text of the entry.
Public propertyCode exampleType
Gets the Microsoft Word field type.
(Inherited from Field.)
Public propertyCode exampleYomi
Gets or sets the yomi (first phonetic character for sorting indexes) for the index entry

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

Defines the text and page number for an index entry, which is used by an INDEX field.

Examples

Shows how to omit entries while populating an INDEX field with entries from XE fields.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Create an INDEX field which will display the page locations of XE fields in the document body
FieldIndex index = (FieldIndex)builder.InsertField(FieldType.FieldIndex, true);

// Set these attributes so that an XE field shows up in the INDEX field's result
// only if it is within the bounds of a bookmark named "MainBookmark", and is of type "A"
index.BookmarkName = "MainBookmark";
index.EntryType = "A";

Assert.AreEqual(" INDEX  \\b MainBookmark \\f A", index.GetFieldCode());

// Our index will take up the first page
builder.InsertBreak(BreakType.PageBreak);

// Start the bookmark that will contain all eligible XE entries
builder.StartBookmark("MainBookmark");

// This entry will be picked up by the INDEX field because it is inside the bookmark
// and its type matches the INDEX field's type
// Note that even though the type is a string, it is defined by only the first character
FieldXE indexEntry = (FieldXE)builder.InsertField(FieldType.FieldIndexEntry, true);
indexEntry.Text = "Index entry 1";
indexEntry.EntryType = "A";

Assert.AreEqual(" XE  \"Index entry 1\" \\f A", indexEntry.GetFieldCode());

// Insert an XE field that will not appear in the INDEX field because it is of the wrong type
builder.InsertBreak(BreakType.PageBreak);
indexEntry = (FieldXE)builder.InsertField(FieldType.FieldIndexEntry, true);
indexEntry.Text = "Index entry 2";
indexEntry.EntryType = "B";

// End the bookmark and insert an XE field afterwards
// It is of the same type as the INDEX field, but will not appear since it is outside of the bookmark
// Note that the INDEX field itself does not have to be within its bookmark
builder.EndBookmark("MainBookmark");
builder.InsertBreak(BreakType.PageBreak);
indexEntry = (FieldXE)builder.InsertField(FieldType.FieldIndexEntry, true);
indexEntry.Text = "Index entry 3";
indexEntry.EntryType = "A";

doc.UpdateFields();
doc.Save(ArtifactsDir + "Field.INDEX.XE.Filtering.docx");
Shows how to modify an INDEX field's appearance while populating it with XE field entries.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Create an INDEX field which will display the page locations of XE fields in the document body
FieldIndex index = (FieldIndex)builder.InsertField(FieldType.FieldIndex, true);
index.LanguageId = "1033";

// Setting this attribute's value to "A" will group all the entries by their first letter
// and place that letter in uppercase above each group
index.Heading = "A";

// Set the table created by the INDEX field to span over 2 columns
index.NumberOfColumns = "2";

// Set any entries with starting letters outside the "a-c" character range to be omitted
index.LetterRange = "a-c";

Assert.AreEqual(" INDEX  \\z 1033 \\h A \\c 2 \\p a-c", index.GetFieldCode());

// These next two XE fields will show up under the "A" heading,
// with their respective text stylings also applied to their page numbers 
builder.InsertBreak(BreakType.PageBreak);
FieldXE indexEntry = (FieldXE)builder.InsertField(FieldType.FieldIndexEntry, true);
indexEntry.Text = "Apple";
indexEntry.IsItalic = true;

Assert.AreEqual(" XE  Apple \\i", indexEntry.GetFieldCode());

builder.InsertBreak(BreakType.PageBreak);
indexEntry = (FieldXE)builder.InsertField(FieldType.FieldIndexEntry, true);
indexEntry.Text = "Apricot";
indexEntry.IsBold = true;

Assert.AreEqual(" XE  Apricot \\b", indexEntry.GetFieldCode());

// Both the next two XE fields will be under a "B" and "C" heading in the INDEX fields table of contents
builder.InsertBreak(BreakType.PageBreak);
indexEntry = (FieldXE)builder.InsertField(FieldType.FieldIndexEntry, true);
indexEntry.Text = "Banana";

builder.InsertBreak(BreakType.PageBreak);
indexEntry = (FieldXE)builder.InsertField(FieldType.FieldIndexEntry, true);
indexEntry.Text = "Cherry";

// All INDEX field entries are sorted alphabetically, so this entry will show up under "A" with the other two
builder.InsertBreak(BreakType.PageBreak);
indexEntry = (FieldXE)builder.InsertField(FieldType.FieldIndexEntry, true);
indexEntry.Text = "Avocado";

// This entry will be excluded because, starting with the letter "D", it is outside the "a-c" range
builder.InsertBreak(BreakType.PageBreak);
indexEntry = (FieldXE)builder.InsertField(FieldType.FieldIndexEntry, true);
indexEntry.Text = "Durian";

doc.UpdateFields();
doc.Save(ArtifactsDir + "Field.INDEX.XE.Formatting.docx");

See Also