Aspose::Words::Paragraph::AppendField method

Paragraph::AppendField(Aspose::Words::Fields::FieldType, bool) method

Appends a field to this paragraph.

System::SharedPtr<Aspose::Words::Fields::Field> Aspose::Words::Paragraph::AppendField(Aspose::Words::Fields::FieldType fieldType, bool updateField)
ParameterTypeDescription
fieldTypeAspose::Words::Fields::FieldTypeThe type of the field to append.
updateFieldboolSpecifies whether to update the field immediately.

ReturnValue

A Field object that represents the appended field.

Examples

Shows various ways of appending fields to a paragraph.

auto doc = MakeObject<Document>();
SharedPtr<Paragraph> paragraph = doc->get_FirstSection()->get_Body()->get_FirstParagraph();

// Below are three ways of appending a field to the end of a paragraph.
// 1 -  Append a DATE field using a field type, and then update it:
paragraph->AppendField(FieldType::FieldDate, true);

// 2 -  Append a TIME field using a field code:
paragraph->AppendField(u" TIME  \\@ \"HH:mm:ss\" ");

// 3 -  Append a QUOTE field using a field code, and get it to display a placeholder value:
paragraph->AppendField(u" QUOTE \"Real value\"", u"Placeholder value");

ASSERT_EQ(u"Placeholder value", doc->get_Range()->get_Fields()->idx_get(2)->get_Result());

// This field will display its placeholder value until we update it.
doc->UpdateFields();

ASSERT_EQ(u"Real value", doc->get_Range()->get_Fields()->idx_get(2)->get_Result());

doc->Save(ArtifactsDir + u"Paragraph.AppendField.docx");

See Also

Paragraph::AppendField(const System::String&) method

Appends a field to this paragraph.

System::SharedPtr<Aspose::Words::Fields::Field> Aspose::Words::Paragraph::AppendField(const System::String &fieldCode)
ParameterTypeDescription
fieldCodeconst System::String&The field code to append (without curly braces).

ReturnValue

A Field object that represents the appended field.

Examples

Shows various ways of appending fields to a paragraph.

auto doc = MakeObject<Document>();
SharedPtr<Paragraph> paragraph = doc->get_FirstSection()->get_Body()->get_FirstParagraph();

// Below are three ways of appending a field to the end of a paragraph.
// 1 -  Append a DATE field using a field type, and then update it:
paragraph->AppendField(FieldType::FieldDate, true);

// 2 -  Append a TIME field using a field code:
paragraph->AppendField(u" TIME  \\@ \"HH:mm:ss\" ");

// 3 -  Append a QUOTE field using a field code, and get it to display a placeholder value:
paragraph->AppendField(u" QUOTE \"Real value\"", u"Placeholder value");

ASSERT_EQ(u"Placeholder value", doc->get_Range()->get_Fields()->idx_get(2)->get_Result());

// This field will display its placeholder value until we update it.
doc->UpdateFields();

ASSERT_EQ(u"Real value", doc->get_Range()->get_Fields()->idx_get(2)->get_Result());

doc->Save(ArtifactsDir + u"Paragraph.AppendField.docx");

See Also

Paragraph::AppendField(const System::String&, const System::String&) method

Appends a field to this paragraph.

System::SharedPtr<Aspose::Words::Fields::Field> Aspose::Words::Paragraph::AppendField(const System::String &fieldCode, const System::String &fieldValue)
ParameterTypeDescription
fieldCodeconst System::String&The field code to append (without curly braces).
fieldValueconst System::String&The field value to append. Pass null for fields that do not have a value.

ReturnValue

A Field object that represents the appended field.

Examples

Shows various ways of appending fields to a paragraph.

auto doc = MakeObject<Document>();
SharedPtr<Paragraph> paragraph = doc->get_FirstSection()->get_Body()->get_FirstParagraph();

// Below are three ways of appending a field to the end of a paragraph.
// 1 -  Append a DATE field using a field type, and then update it:
paragraph->AppendField(FieldType::FieldDate, true);

// 2 -  Append a TIME field using a field code:
paragraph->AppendField(u" TIME  \\@ \"HH:mm:ss\" ");

// 3 -  Append a QUOTE field using a field code, and get it to display a placeholder value:
paragraph->AppendField(u" QUOTE \"Real value\"", u"Placeholder value");

ASSERT_EQ(u"Placeholder value", doc->get_Range()->get_Fields()->idx_get(2)->get_Result());

// This field will display its placeholder value until we update it.
doc->UpdateFields();

ASSERT_EQ(u"Real value", doc->get_Range()->get_Fields()->idx_get(2)->get_Result());

doc->Save(ArtifactsDir + u"Paragraph.AppendField.docx");

See Also