Aspose::Words::Fields::FieldStyleRef class

FieldStyleRef class

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

class FieldStyleRef : public Field,
                      public IFieldCodeTokenInfoProvider

Methods

MethodDescription
get_InsertParagraphNumber()Gets or sets whether to insert the paragraph number of the referenced paragraph exactly as it appears in the document.
get_InsertParagraphNumberInFullContext()Gets or sets whether to insert the paragraph number of the referenced paragraph in full context.
get_InsertParagraphNumberInRelativeContext()Gets or sets whether to insert the paragraph number of the referenced paragraph in relative context.
get_InsertRelativePosition()Gets or sets whether to insert the relative position of the referenced paragraph.
get_SearchFromBottom()Gets or sets whether to search from the bottom of the current page, rather from the top.
get_StyleName()Gets or sets the name of the style by which the text to search for is formatted.
get_SuppressNonDelimiters()Gets or sets whether to suppress non-delimiter characters.
set_InsertParagraphNumber(bool)Sets whether to insert the paragraph number of the referenced paragraph exactly as it appears in the document.
set_InsertParagraphNumberInFullContext(bool)Sets whether to insert the paragraph number of the referenced paragraph in full context.
set_InsertParagraphNumberInRelativeContext(bool)Sets whether to insert the paragraph number of the referenced paragraph in relative context.
set_InsertRelativePosition(bool)Sets whether to insert the relative position of the referenced paragraph.
set_SearchFromBottom(bool)Sets whether to search from the bottom of the current page, rather from the top.
set_StyleName(const System::String &)Sets the name of the style by which the text to search for is formatted.
set_SuppressNonDelimiters(bool)Sets whether to suppress non-delimiter characters.
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).
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.
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.
get_DisplayResult()Gets the text that represents the displayed field result.
get_End() constGets the node that represents the field end.
get_Format()Gets a FieldFormat object that provides typed access to field’s formatting.
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_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_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() constGets the node that represents the start of the field.
virtual get_Type() constGets the Microsoft Word field type.
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)Sets whether the field is locked (should not recalculate its result).
set_LocaleId(int32_t)Sets the LCID of the field.
set_Result(const System::String &)Sets text that is between the field separator and field end.

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.

auto doc = System::MakeObject<Aspose::Words::Document>();
auto builder = System::MakeObject<Aspose::Words::DocumentBuilder>(doc);

// Create a list based using a Microsoft Word list template.
System::SharedPtr<Aspose::Words::Lists::List> list = doc->get_Lists()->Add(Lists::ListTemplate::NumberDefault);

// This generated list will display "1.a )".
// Space before the bracket is a non-delimiter character, which we can suppress.
list->get_ListLevels()->idx_get(0)->set_NumberFormat(u"\x0000" u".");
list->get_ListLevels()->idx_get(1)->set_NumberFormat(u"\x0001" u" )");

// Add text and apply paragraph styles that STYLEREF fields will reference.
builder->get_ListFormat()->set_List(list);
builder->get_ListFormat()->ListIndent();
builder->get_ParagraphFormat()->set_Style(doc->get_Styles()->idx_get(u"List Paragraph"));
builder->Writeln(u"Item 1");
builder->get_ParagraphFormat()->set_Style(doc->get_Styles()->idx_get(u"Quote"));
builder->Writeln(u"Item 2");
builder->get_ParagraphFormat()->set_Style(doc->get_Styles()->idx_get(u"List Paragraph"));
builder->Writeln(u"Item 3");
builder->get_ListFormat()->RemoveNumbers();
builder->get_ParagraphFormat()->set_Style(doc->get_Styles()->idx_get(u"Normal"));

// Place a STYLEREF field in the header and display the first "List Paragraph"-styled text in the document.
builder->MoveToHeaderFooter(HeaderFooterType::HeaderPrimary);
auto field = System::ExplicitCast<Aspose::Words::Fields::FieldStyleRef>(builder->InsertField(FieldType::FieldStyleRef, true));
field->set_StyleName(u"List Paragraph");

// Place a STYLEREF field in the footer, and have it display the last text.
builder->MoveToHeaderFooter(HeaderFooterType::FooterPrimary);
field = System::ExplicitCast<Aspose::Words::Fields::FieldStyleRef>(builder->InsertField(FieldType::FieldStyleRef, true));
field->set_StyleName(u"List Paragraph");
field->set_SearchFromBottom(true);

builder->MoveToDocumentEnd();

// We can also use STYLEREF fields to reference the list numbers of lists.
builder->Write(u"\nParagraph number: ");
field = System::ExplicitCast<Aspose::Words::Fields::FieldStyleRef>(builder->InsertField(FieldType::FieldStyleRef, true));
field->set_StyleName(u"Quote");
field->set_InsertParagraphNumber(true);

builder->Write(u"\nParagraph number, relative context: ");
field = System::ExplicitCast<Aspose::Words::Fields::FieldStyleRef>(builder->InsertField(FieldType::FieldStyleRef, true));
field->set_StyleName(u"Quote");
field->set_InsertParagraphNumberInRelativeContext(true);

builder->Write(u"\nParagraph number, full context: ");
field = System::ExplicitCast<Aspose::Words::Fields::FieldStyleRef>(builder->InsertField(FieldType::FieldStyleRef, true));
field->set_StyleName(u"Quote");
field->set_InsertParagraphNumberInFullContext(true);

builder->Write(u"\nParagraph number, full context, non-delimiter chars suppressed: ");
field = System::ExplicitCast<Aspose::Words::Fields::FieldStyleRef>(builder->InsertField(FieldType::FieldStyleRef, true));
field->set_StyleName(u"Quote");
field->set_InsertParagraphNumberInFullContext(true);
field->set_SuppressNonDelimiters(true);

doc->UpdatePageLayout();
doc->UpdateFields();
doc->Save(get_ArtifactsDir() + u"Field.STYLEREF.docx");

See Also