Aspose::Words::Fields::FieldAutoTextList class

FieldAutoTextList class

Implements the AUTOTEXTLIST field. To learn more, visit the Working with Fields documentation article.

class FieldAutoTextList : public Aspose::Words::Fields::Field,
                          public Aspose::Words::Fields::IFieldCodeTokenInfoProvider

Methods

MethodDescription
get_DisplayResult()Gets the text that represents the displayed field result.
get_End() constGets the node that represents the field end.
get_EntryName()Gets or sets the name of the AutoText entry.
get_FieldEnd() constGets the node that represents the field end.
get_FieldStart() constGets the node that represents the start of the field.
get_Format()Gets a FieldFormat object that provides typed access to field’s formatting.
get_IsDirty()Gets whether the current result of the field is no longer correct (stale) due to other modifications made to the document.
get_IsLocked()Gets or sets whether the field is locked (should not recalculate its result).
get_ListStyle()Gets or sets the name of the style on which the list to contain entries is based.
get_LocaleId()Gets or sets the LCID of the field.
get_Result()Gets or sets text that is between the field separator and field end.
get_ScreenTip()Gets or sets the text of the ScreenTip to show.
get_Separator()Gets the node that represents the field separator. Can be null.
get_Start() constGets the node that represents the start of the field.
virtual get_Type() constGets the Microsoft Word field type.
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
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_EntryName(const System::String&)Setter for Aspose::Words::Fields::FieldAutoTextList::get_EntryName.
set_IsDirty(bool)Sets whether the current result of the field is no longer correct (stale) due to other modifications made to the document.
set_IsLocked(bool)Setter for Aspose::Words::Fields::Field::get_IsLocked.
set_ListStyle(const System::String&)Setter for Aspose::Words::Fields::FieldAutoTextList::get_ListStyle.
set_LocaleId(int32_t)Setter for Aspose::Words::Fields::Field::get_LocaleId.
set_Result(const System::String&)Setter for Aspose::Words::Fields::Field::get_Result.
set_ScreenTip(const System::String&)Setter for Aspose::Words::Fields::FieldAutoTextList::get_ScreenTip.
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 use an AUTOTEXTLIST field to select from a list of AutoText entries.

void FieldAutoTextList_()
{
    auto doc = MakeObject<Document>();

    // Create a glossary document and populate it with auto text entries.
    doc->set_GlossaryDocument(MakeObject<GlossaryDocument>());
    AppendAutoTextEntry(doc->get_GlossaryDocument(), u"AutoText 1", u"Contents of AutoText 1");
    AppendAutoTextEntry(doc->get_GlossaryDocument(), u"AutoText 2", u"Contents of AutoText 2");
    AppendAutoTextEntry(doc->get_GlossaryDocument(), u"AutoText 3", u"Contents of AutoText 3");

    auto builder = MakeObject<DocumentBuilder>(doc);

    // Create an AUTOTEXTLIST field and set the text that the field will display in Microsoft Word.
    // Set the text to prompt the user to right-click this field to select an AutoText building block,
    // whose contents the field will display.
    auto field = System::ExplicitCast<FieldAutoTextList>(builder->InsertField(FieldType::FieldAutoTextList, true));
    field->set_EntryName(u"Right click here to select an AutoText block");
    field->set_ListStyle(u"Heading 1");
    field->set_ScreenTip(u"Hover tip text for AutoTextList goes here");

    ASSERT_EQ(String(u" AUTOTEXTLIST  \"Right click here to select an AutoText block\" ") + u"\\s \"Heading 1\" " +
                  u"\\t \"Hover tip text for AutoTextList goes here\"",
              field->GetFieldCode());

    doc->Save(ArtifactsDir + u"Field.AUTOTEXTLIST.dotx");
}

static void AppendAutoTextEntry(SharedPtr<GlossaryDocument> glossaryDoc, String name, String contents)
{
    auto buildingBlock = MakeObject<BuildingBlock>(glossaryDoc);
    buildingBlock->set_Name(name);
    buildingBlock->set_Gallery(BuildingBlockGallery::AutoText);
    buildingBlock->set_Category(u"General");
    buildingBlock->set_Behavior(BuildingBlockBehavior::Paragraph);

    auto section = MakeObject<Section>(glossaryDoc);
    section->AppendChild(MakeObject<Body>(glossaryDoc));
    section->get_Body()->AppendParagraph(contents);
    buildingBlock->AppendChild(section);

    glossaryDoc->AppendChild(buildingBlock);
}

See Also