Aspose::Words::Fields::FieldXE class
Contents
[
Hide
]FieldXE class
Implements the XE field. To learn more, visit the Working with Fields documentation article.
class FieldXE : public Aspose::Words::Fields::Field,
public Aspose::Words::Fields::IFieldCodeTokenInfoProvider
Methods
Method | Description |
---|---|
get_DisplayResult() | Gets the text that represents the displayed field result. |
get_End() const | Gets the node that represents the field end. |
get_EntryType() | Gets or sets an index entry type. |
get_FieldEnd() const | Gets the node that represents the field end. |
get_FieldStart() const | Gets the node that represents the start of the field. |
get_Format() | Gets a FieldFormat object that provides typed access to field’s formatting. |
get_IsBold() | Gets or sets whether to apply bold formatting to the entry’s page number. |
get_IsDirty() | Gets or sets whether the current result of the field is no longer correct (stale) due to other modifications made to the document. |
get_IsItalic() | Gets or sets whether to apply italic formatting to the entry’s page number. |
get_IsLocked() | Gets or sets whether the field is locked (should not recalculate its result). |
get_LocaleId() | Gets or sets the LCID of the field. |
get_PageNumberReplacement() | Gets or sets text used in place of a page number. |
get_PageRangeBookmarkName() | Gets or sets the name of the bookmark that marks a range of pages that is inserted as the entry’s page number. |
get_Result() | Gets or sets text that is between the field separator and field end. |
get_Separator() | Gets the node that represents the field separator. Can be null. |
get_Start() const | Gets the node that represents the start of the field. |
get_Text() | Gets or sets the text of the entry. |
virtual get_Type() const | Gets the Microsoft Word field type. |
get_Yomi() | Gets or sets the yomi (first phonetic character for sorting indexes) for the index entry. |
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). |
GetType() const override | |
Is(const System::TypeInfo&) const override | |
virtual 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. |
set_EntryType(const System::String&) | Setter for Aspose::Words::Fields::FieldXE::get_EntryType. |
set_IsBold(bool) | Setter for Aspose::Words::Fields::FieldXE::get_IsBold. |
set_IsDirty(bool) | Setter for Aspose::Words::Fields::Field::get_IsDirty. |
set_IsItalic(bool) | Setter for Aspose::Words::Fields::FieldXE::get_IsItalic. |
set_IsLocked(bool) | Setter for Aspose::Words::Fields::Field::get_IsLocked. |
set_LocaleId(int32_t) | Setter for Aspose::Words::Fields::Field::get_LocaleId. |
set_PageNumberReplacement(const System::String&) | Setter for Aspose::Words::Fields::FieldXE::get_PageNumberReplacement. |
set_PageRangeBookmarkName(const System::String&) | Setter for Aspose::Words::Fields::FieldXE::get_PageRangeBookmarkName. |
set_Result(const System::String&) | Setter for Aspose::Words::Fields::Field::get_Result. |
set_Text(const System::String&) | Setter for Aspose::Words::Fields::FieldXE::get_Text. |
set_Yomi(const System::String&) | Setter for Aspose::Words::Fields::FieldXE::get_Yomi. |
static Type() | |
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. |
Examples
Shows how to create an INDEX field, and then use XE fields to populate it with entries.
auto doc = System::MakeObject<Aspose::Words::Document>();
auto builder = System::MakeObject<Aspose::Words::DocumentBuilder>(doc);
// Create an INDEX field which will display an entry for each XE field found in the document.
// Each entry will display the XE field's Text property value on the left side
// and the page containing the XE field on the right.
// If the XE fields have the same value in their "Text" property,
// the INDEX field will group them into one entry.
auto index = System::ExplicitCast<Aspose::Words::Fields::FieldIndex>(builder->InsertField(Aspose::Words::Fields::FieldType::FieldIndex, true));
// Configure the INDEX field only to display XE fields that are within the bounds
// of a bookmark named "MainBookmark", and whose "EntryType" properties have a value of "A".
// For both INDEX and XE fields, the "EntryType" property only uses the first character of its string value.
index->set_BookmarkName(u"MainBookmark");
index->set_EntryType(u"A");
ASSERT_EQ(u" INDEX \\b MainBookmark \\f A", index->GetFieldCode());
// On a new page, start the bookmark with a name that matches the value
// of the INDEX field's "BookmarkName" property.
builder->InsertBreak(Aspose::Words::BreakType::PageBreak);
builder->StartBookmark(u"MainBookmark");
// The INDEX field will pick up this entry because it is inside the bookmark,
// and its entry type also matches the INDEX field's entry type.
auto indexEntry = System::ExplicitCast<Aspose::Words::Fields::FieldXE>(builder->InsertField(Aspose::Words::Fields::FieldType::FieldIndexEntry, true));
indexEntry->set_Text(u"Index entry 1");
indexEntry->set_EntryType(u"A");
ASSERT_EQ(u" XE \"Index entry 1\" \\f A", indexEntry->GetFieldCode());
// Insert an XE field that will not appear in the INDEX because the entry types do not match.
builder->InsertBreak(Aspose::Words::BreakType::PageBreak);
indexEntry = System::ExplicitCast<Aspose::Words::Fields::FieldXE>(builder->InsertField(Aspose::Words::Fields::FieldType::FieldIndexEntry, true));
indexEntry->set_Text(u"Index entry 2");
indexEntry->set_EntryType(u"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 the bookmark's boundaries.
builder->EndBookmark(u"MainBookmark");
builder->InsertBreak(Aspose::Words::BreakType::PageBreak);
indexEntry = System::ExplicitCast<Aspose::Words::Fields::FieldXE>(builder->InsertField(Aspose::Words::Fields::FieldType::FieldIndexEntry, true));
indexEntry->set_Text(u"Index entry 3");
indexEntry->set_EntryType(u"A");
doc->UpdatePageLayout();
doc->UpdateFields();
doc->Save(get_ArtifactsDir() + u"Field.INDEX.XE.Filtering.docx");
Shows how to populate an INDEX field with entries using XE fields, and also modify its appearance.
auto doc = System::MakeObject<Aspose::Words::Document>();
auto builder = System::MakeObject<Aspose::Words::DocumentBuilder>(doc);
// Create an INDEX field which will display an entry for each XE field found in the document.
// Each entry will display the XE field's Text property value on the left side,
// and the number of the page that contains the XE field on the right.
// If the XE fields have the same value in their "Text" property,
// the INDEX field will group them into one entry.
auto index = System::ExplicitCast<Aspose::Words::Fields::FieldIndex>(builder->InsertField(Aspose::Words::Fields::FieldType::FieldIndex, true));
index->set_LanguageId(u"1033");
// Setting this property's value to "A" will group all the entries by their first letter,
// and place that letter in uppercase above each group.
index->set_Heading(u"A");
// Set the table created by the INDEX field to span over 2 columns.
index->set_NumberOfColumns(u"2");
// Set any entries with starting letters outside the "a-c" character range to be omitted.
index->set_LetterRange(u"a-c");
ASSERT_EQ(u" 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(Aspose::Words::BreakType::PageBreak);
auto indexEntry = System::ExplicitCast<Aspose::Words::Fields::FieldXE>(builder->InsertField(Aspose::Words::Fields::FieldType::FieldIndexEntry, true));
indexEntry->set_Text(u"Apple");
indexEntry->set_IsItalic(true);
ASSERT_EQ(u" XE Apple \\i", indexEntry->GetFieldCode());
builder->InsertBreak(Aspose::Words::BreakType::PageBreak);
indexEntry = System::ExplicitCast<Aspose::Words::Fields::FieldXE>(builder->InsertField(Aspose::Words::Fields::FieldType::FieldIndexEntry, true));
indexEntry->set_Text(u"Apricot");
indexEntry->set_IsBold(true);
ASSERT_EQ(u" 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(Aspose::Words::BreakType::PageBreak);
indexEntry = System::ExplicitCast<Aspose::Words::Fields::FieldXE>(builder->InsertField(Aspose::Words::Fields::FieldType::FieldIndexEntry, true));
indexEntry->set_Text(u"Banana");
builder->InsertBreak(Aspose::Words::BreakType::PageBreak);
indexEntry = System::ExplicitCast<Aspose::Words::Fields::FieldXE>(builder->InsertField(Aspose::Words::Fields::FieldType::FieldIndexEntry, true));
indexEntry->set_Text(u"Cherry");
// INDEX fields sort all entries alphabetically, so this entry will show up under "A" with the other two.
builder->InsertBreak(Aspose::Words::BreakType::PageBreak);
indexEntry = System::ExplicitCast<Aspose::Words::Fields::FieldXE>(builder->InsertField(Aspose::Words::Fields::FieldType::FieldIndexEntry, true));
indexEntry->set_Text(u"Avocado");
// This entry will not appear because it starts with the letter "D",
// which is outside the "a-c" character range that the INDEX field's LetterRange property defines.
builder->InsertBreak(Aspose::Words::BreakType::PageBreak);
indexEntry = System::ExplicitCast<Aspose::Words::Fields::FieldXE>(builder->InsertField(Aspose::Words::Fields::FieldType::FieldIndexEntry, true));
indexEntry->set_Text(u"Durian");
doc->UpdatePageLayout();
doc->UpdateFields();
doc->Save(get_ArtifactsDir() + u"Field.INDEX.XE.Formatting.docx");
See Also
- Class Field
- Namespace Aspose::Words::Fields
- Library Aspose.Words for C++