search/mag_sel search/close

Represents a single built-in or user-defined style.

Examples

Shows how to create and apply a custom style.

auto doc = MakeObject<Document>();
SharedPtr<Style> style = doc->get_Styles()->Add(StyleType::Paragraph, u"MyStyle");
style->get_Font()->set_Name(u"Times New Roman");
style->get_Font()->set_Size(16);
style->get_Font()->set_Color(System::Drawing::Color::get_Navy());
auto builder = MakeObject<DocumentBuilder>(doc);
// Apply one of the styles from the document to the paragraph that the document builder is creating.
builder->get_ParagraphFormat()->set_Style(doc->get_Styles()->idx_get(u"MyStyle"));
builder->Writeln(u"Hello world!");
SharedPtr<Style> firstParagraphStyle = doc->get_FirstSection()->get_Body()->get_FirstParagraph()->get_ParagraphFormat()->get_Style();
ASPOSE_ASSERT_EQ(style, firstParagraphStyle);
// Remove our custom style from the document's styles collection.
doc->get_Styles()->idx_get(u"MyStyle")->Remove();
firstParagraphStyle = doc->get_FirstSection()->get_Body()->get_FirstParagraph()->get_ParagraphFormat()->get_Style();
// Any text that used a removed style reverts to the default formatting.
ASSERT_FALSE(doc->get_Styles()->LINQ_Any([](SharedPtr<Style> s) { return s->get_Name() == u"MyStyle"; }));
ASSERT_EQ(u"Times New Roman", firstParagraphStyle->get_Font()->get_Name());
ASPOSE_ASSERT_EQ(12.0, firstParagraphStyle->get_Font()->get_Size());
ASSERT_EQ(System::Drawing::Color::Empty.ToArgb(), firstParagraphStyle->get_Font()->get_Color().ToArgb());

Shows how to create and use a paragraph style with list formatting.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Create a custom paragraph style.
SharedPtr<Style> style = doc->get_Styles()->Add(StyleType::Paragraph, u"MyStyle1");
style->get_Font()->set_Size(24);
style->get_Font()->set_Name(u"Verdana");
style->get_ParagraphFormat()->set_SpaceAfter(12);
// Create a list and make sure the paragraphs that use this style will use this list.
style->get_ListFormat()->set_List(doc->get_Lists()->Add(ListTemplate::BulletDefault));
style->get_ListFormat()->set_ListLevelNumber(0);
// Apply the paragraph style to the document builder's current paragraph, and then add some text.
builder->get_ParagraphFormat()->set_Style(style);
builder->Writeln(u"Hello World: MyStyle1, bulleted list.");
// Change the document builder's style to one that has no list formatting and write another paragraph.
builder->get_ParagraphFormat()->set_Style(doc->get_Styles()->idx_get(u"Normal"));
builder->Writeln(u"Hello World: Normal.");
builder->get_Document()->Save(ArtifactsDir + u"Styles.ParagraphStyleBulletedList.docx");

#include <Aspose.Words.Cpp/Style.h>

+ Inheritance diagram for Aspose::Words::Style:

Public Member Functions

bool Equals (SharedPtr< Style > style)
 Compares with the specified style. Styles Istds are compared for built-in styles only. Styles defaults are not included in comparison. Base style, linked style and next paragraph style are recursively compared. More...
 
ArrayPtr< Stringget_Aliases ()
 Gets all aliases of this style. If style has no aliases then empty array of string is returned. More...
 
String get_BaseStyleName ()
 Gets/sets the name of the style this style is based on. More...
 
bool get_BuiltIn ()
 True if this style is one of the built-in styles in MS Word. More...
 
SharedPtr< DocumentBaseget_Document ()
 Gets the owner document. More...
 
SharedPtr< Fontget_Font ()
 Gets the character formatting of the style. More...
 
bool get_IsHeading ()
 True when the style is one of the built-in Heading styles. More...
 
bool get_IsQuickStyle () const
 Specifies whether this style is shown in the Quick Style gallery inside MS Word UI. More...
 
String get_LinkedStyleName ()
 Gets the name of the Style linked to this one. Returns Empty string if no styles are linked. More...
 
SharedPtr< Listget_List ()
 Gets the list that defines formatting of this list style. More...
 
SharedPtr< ListFormatget_ListFormat ()
 Provides access to the list formatting properties of a paragraph style. More...
 
String get_Name () const
 Gets or sets the name of the style. More...
 
String get_NextParagraphStyleName ()
 Gets/sets the name of the style to be applied automatically to a new paragraph inserted after a paragraph formatted with the specified style. More...
 
SharedPtr< ParagraphFormatget_ParagraphFormat ()
 Gets the paragraph formatting of the style. More...
 
StyleIdentifier get_StyleIdentifier () const
 Gets the locale independent style identifier for a built-in style. More...
 
SharedPtr< StyleCollectionget_Styles () const
 Gets the collection of styles this style belongs to. More...
 
StyleType get_Type () const
 Gets the style type (paragraph or character). More...
 
virtual const TypeInfoGetType () const override
 
virtual bool Is (const TypeInfo &target) const override
 
void Remove ()
 Removes the specified style from the document. More...
 
void set_BaseStyleName (String value)
 Setter for get_BaseStyleName. More...
 
void set_IsQuickStyle (bool value)
 Setter for get_IsQuickStyle. More...
 
void set_Name (String value)
 Setter for get_Name. More...
 
void set_NextParagraphStyleName (String value)
 Setter for get_NextParagraphStyleName. More...
 

Static Public Member Functions

static const TypeInfoType ()
 

Member Function Documentation

◆ Equals()

bool Aspose::Words::Style::Equals ( System::SharedPtr< Aspose::Words::Style style)

Compares with the specified style. Styles Istds are compared for built-in styles only. Styles defaults are not included in comparison. Base style, linked style and next paragraph style are recursively compared.

Examples

Shows how to use style aliases.

auto doc = MakeObject<Document>(MyDir + u"Style with alias.docx");
// This document contains a style named "MyStyle,MyStyle Alias 1,MyStyle Alias 2".
// If a style's name has multiple values separated by commas, each clause is a separate alias.
SharedPtr<Style> style = doc->get_Styles()->idx_get(u"MyStyle");
ASPOSE_ASSERT_EQ(MakeArray<String>({u"MyStyle Alias 1", u"MyStyle Alias 2"}), style->get_Aliases());
ASSERT_EQ(u"Title", style->get_BaseStyleName());
ASSERT_EQ(u"MyStyle Char", style->get_LinkedStyleName());
// We can reference a style using its alias, as well as its name.
ASPOSE_ASSERT_EQ(doc->get_Styles()->idx_get(u"MyStyle Alias 1"), doc->get_Styles()->idx_get(u"MyStyle Alias 2"));
auto builder = MakeObject<DocumentBuilder>(doc);
builder->MoveToDocumentEnd();
builder->get_ParagraphFormat()->set_Style(doc->get_Styles()->idx_get(u"MyStyle Alias 1"));
builder->Writeln(u"Hello world!");
builder->get_ParagraphFormat()->set_Style(doc->get_Styles()->idx_get(u"MyStyle Alias 2"));
builder->Write(u"Hello again!");
ASPOSE_ASSERT_EQ(doc->get_FirstSection()->get_Body()->get_Paragraphs()->idx_get(0)->get_ParagraphFormat()->get_Style(),
doc->get_FirstSection()->get_Body()->get_Paragraphs()->idx_get(1)->get_ParagraphFormat()->get_Style());

◆ get_Aliases()

System::ArrayPtr<System::String> Aspose::Words::Style::get_Aliases ( )

Gets all aliases of this style. If style has no aliases then empty array of string is returned.

Examples

Shows how to use style aliases.

auto doc = MakeObject<Document>(MyDir + u"Style with alias.docx");
// This document contains a style named "MyStyle,MyStyle Alias 1,MyStyle Alias 2".
// If a style's name has multiple values separated by commas, each clause is a separate alias.
SharedPtr<Style> style = doc->get_Styles()->idx_get(u"MyStyle");
ASPOSE_ASSERT_EQ(MakeArray<String>({u"MyStyle Alias 1", u"MyStyle Alias 2"}), style->get_Aliases());
ASSERT_EQ(u"Title", style->get_BaseStyleName());
ASSERT_EQ(u"MyStyle Char", style->get_LinkedStyleName());
// We can reference a style using its alias, as well as its name.
ASPOSE_ASSERT_EQ(doc->get_Styles()->idx_get(u"MyStyle Alias 1"), doc->get_Styles()->idx_get(u"MyStyle Alias 2"));
auto builder = MakeObject<DocumentBuilder>(doc);
builder->MoveToDocumentEnd();
builder->get_ParagraphFormat()->set_Style(doc->get_Styles()->idx_get(u"MyStyle Alias 1"));
builder->Writeln(u"Hello world!");
builder->get_ParagraphFormat()->set_Style(doc->get_Styles()->idx_get(u"MyStyle Alias 2"));
builder->Write(u"Hello again!");
ASPOSE_ASSERT_EQ(doc->get_FirstSection()->get_Body()->get_Paragraphs()->idx_get(0)->get_ParagraphFormat()->get_Style(),
doc->get_FirstSection()->get_Body()->get_Paragraphs()->idx_get(1)->get_ParagraphFormat()->get_Style());

◆ get_BaseStyleName()

System::String Aspose::Words::Style::get_BaseStyleName ( )

Gets/sets the name of the style this style is based on.

Examples

Shows how to use style aliases.

auto doc = MakeObject<Document>(MyDir + u"Style with alias.docx");
// This document contains a style named "MyStyle,MyStyle Alias 1,MyStyle Alias 2".
// If a style's name has multiple values separated by commas, each clause is a separate alias.
SharedPtr<Style> style = doc->get_Styles()->idx_get(u"MyStyle");
ASPOSE_ASSERT_EQ(MakeArray<String>({u"MyStyle Alias 1", u"MyStyle Alias 2"}), style->get_Aliases());
ASSERT_EQ(u"Title", style->get_BaseStyleName());
ASSERT_EQ(u"MyStyle Char", style->get_LinkedStyleName());
// We can reference a style using its alias, as well as its name.
ASPOSE_ASSERT_EQ(doc->get_Styles()->idx_get(u"MyStyle Alias 1"), doc->get_Styles()->idx_get(u"MyStyle Alias 2"));
auto builder = MakeObject<DocumentBuilder>(doc);
builder->MoveToDocumentEnd();
builder->get_ParagraphFormat()->set_Style(doc->get_Styles()->idx_get(u"MyStyle Alias 1"));
builder->Writeln(u"Hello world!");
builder->get_ParagraphFormat()->set_Style(doc->get_Styles()->idx_get(u"MyStyle Alias 2"));
builder->Write(u"Hello again!");
ASPOSE_ASSERT_EQ(doc->get_FirstSection()->get_Body()->get_Paragraphs()->idx_get(0)->get_ParagraphFormat()->get_Style(),
doc->get_FirstSection()->get_Body()->get_Paragraphs()->idx_get(1)->get_ParagraphFormat()->get_Style());

◆ get_BuiltIn()

bool Aspose::Words::Style::get_BuiltIn ( )

True if this style is one of the built-in styles in MS Word.

Examples

Shows how to differentiate custom styles from built-in styles.

auto doc = MakeObject<Document>();
// When we create a document using Microsoft Word, or programmatically using Aspose.Words,
// the document will come with a collection of styles to apply to its text to modify its appearance.
// We can access these built-in styles via the document's "Styles" collection.
// These styles will all have the "BuiltIn" flag set to "true".
SharedPtr<Style> style = doc->get_Styles()->idx_get(u"Emphasis");
ASSERT_TRUE(style->get_BuiltIn());
// Create a custom style and add it to the collection.
// Custom styles such as this will have the "BuiltIn" flag set to "false".
style = doc->get_Styles()->Add(StyleType::Character, u"MyStyle");
style->get_Font()->set_Color(System::Drawing::Color::get_Navy());
style->get_Font()->set_Name(u"Courier New");
ASSERT_FALSE(style->get_BuiltIn());

◆ get_Document()

System::SharedPtr<Aspose::Words::DocumentBase> Aspose::Words::Style::get_Document ( )

Gets the owner document.

Examples

Shows how to access a document's style collection.

auto doc = MakeObject<Document>();
ASSERT_EQ(4, doc->get_Styles()->get_Count());
// Enumerate and list all the styles that a document created using Aspose.Words contains by default.
{
SharedPtr<System::Collections::Generic::IEnumerator<SharedPtr<Style>>> stylesEnum = doc->get_Styles()->GetEnumerator();
while (stylesEnum->MoveNext())
{
SharedPtr<Style> curStyle = stylesEnum->get_Current();
std::cout << String::Format(u"Style name:\t\"{0}\", of type \"{1}\"", curStyle->get_Name(), curStyle->get_Type()) << std::endl;
std::cout << "\tSubsequent style:\t" << curStyle->get_NextParagraphStyleName() << std::endl;
std::cout << String::Format(u"\tIs heading:\t\t\t{0}", curStyle->get_IsHeading()) << std::endl;
std::cout << String::Format(u"\tIs QuickStyle:\t\t{0}", curStyle->get_IsQuickStyle()) << std::endl;
ASPOSE_ASSERT_EQ(doc, curStyle->get_Document());
}
}

◆ get_Font()

System::SharedPtr<Aspose::Words::Font> Aspose::Words::Style::get_Font ( )

Gets the character formatting of the style.

For list styles this property returns null.

Examples

Shows how to create and apply a custom style.

auto doc = MakeObject<Document>();
SharedPtr<Style> style = doc->get_Styles()->Add(StyleType::Paragraph, u"MyStyle");
style->get_Font()->set_Name(u"Times New Roman");
style->get_Font()->set_Size(16);
style->get_Font()->set_Color(System::Drawing::Color::get_Navy());
auto builder = MakeObject<DocumentBuilder>(doc);
// Apply one of the styles from the document to the paragraph that the document builder is creating.
builder->get_ParagraphFormat()->set_Style(doc->get_Styles()->idx_get(u"MyStyle"));
builder->Writeln(u"Hello world!");
SharedPtr<Style> firstParagraphStyle = doc->get_FirstSection()->get_Body()->get_FirstParagraph()->get_ParagraphFormat()->get_Style();
ASPOSE_ASSERT_EQ(style, firstParagraphStyle);
// Remove our custom style from the document's styles collection.
doc->get_Styles()->idx_get(u"MyStyle")->Remove();
firstParagraphStyle = doc->get_FirstSection()->get_Body()->get_FirstParagraph()->get_ParagraphFormat()->get_Style();
// Any text that used a removed style reverts to the default formatting.
ASSERT_FALSE(doc->get_Styles()->LINQ_Any([](SharedPtr<Style> s) { return s->get_Name() == u"MyStyle"; }));
ASSERT_EQ(u"Times New Roman", firstParagraphStyle->get_Font()->get_Name());
ASPOSE_ASSERT_EQ(12.0, firstParagraphStyle->get_Font()->get_Size());
ASSERT_EQ(System::Drawing::Color::Empty.ToArgb(), firstParagraphStyle->get_Font()->get_Color().ToArgb());

Shows how to create and use a paragraph style with list formatting.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Create a custom paragraph style.
SharedPtr<Style> style = doc->get_Styles()->Add(StyleType::Paragraph, u"MyStyle1");
style->get_Font()->set_Size(24);
style->get_Font()->set_Name(u"Verdana");
style->get_ParagraphFormat()->set_SpaceAfter(12);
// Create a list and make sure the paragraphs that use this style will use this list.
style->get_ListFormat()->set_List(doc->get_Lists()->Add(ListTemplate::BulletDefault));
style->get_ListFormat()->set_ListLevelNumber(0);
// Apply the paragraph style to the document builder's current paragraph, and then add some text.
builder->get_ParagraphFormat()->set_Style(style);
builder->Writeln(u"Hello World: MyStyle1, bulleted list.");
// Change the document builder's style to one that has no list formatting and write another paragraph.
builder->get_ParagraphFormat()->set_Style(doc->get_Styles()->idx_get(u"Normal"));
builder->Writeln(u"Hello World: Normal.");
builder->get_Document()->Save(ArtifactsDir + u"Styles.ParagraphStyleBulletedList.docx");

◆ get_IsHeading()

bool Aspose::Words::Style::get_IsHeading ( )

True when the style is one of the built-in Heading styles.

Examples

Shows how to access a document's style collection.

auto doc = MakeObject<Document>();
ASSERT_EQ(4, doc->get_Styles()->get_Count());
// Enumerate and list all the styles that a document created using Aspose.Words contains by default.
{
SharedPtr<System::Collections::Generic::IEnumerator<SharedPtr<Style>>> stylesEnum = doc->get_Styles()->GetEnumerator();
while (stylesEnum->MoveNext())
{
SharedPtr<Style> curStyle = stylesEnum->get_Current();
std::cout << String::Format(u"Style name:\t\"{0}\", of type \"{1}\"", curStyle->get_Name(), curStyle->get_Type()) << std::endl;
std::cout << "\tSubsequent style:\t" << curStyle->get_NextParagraphStyleName() << std::endl;
std::cout << String::Format(u"\tIs heading:\t\t\t{0}", curStyle->get_IsHeading()) << std::endl;
std::cout << String::Format(u"\tIs QuickStyle:\t\t{0}", curStyle->get_IsQuickStyle()) << std::endl;
ASPOSE_ASSERT_EQ(doc, curStyle->get_Document());
}
}

◆ get_IsQuickStyle()

bool Aspose::Words::Style::get_IsQuickStyle ( ) const

Specifies whether this style is shown in the Quick Style gallery inside MS Word UI.

Examples

Shows how to access a document's style collection.

auto doc = MakeObject<Document>();
ASSERT_EQ(4, doc->get_Styles()->get_Count());
// Enumerate and list all the styles that a document created using Aspose.Words contains by default.
{
SharedPtr<System::Collections::Generic::IEnumerator<SharedPtr<Style>>> stylesEnum = doc->get_Styles()->GetEnumerator();
while (stylesEnum->MoveNext())
{
SharedPtr<Style> curStyle = stylesEnum->get_Current();
std::cout << String::Format(u"Style name:\t\"{0}\", of type \"{1}\"", curStyle->get_Name(), curStyle->get_Type()) << std::endl;
std::cout << "\tSubsequent style:\t" << curStyle->get_NextParagraphStyleName() << std::endl;
std::cout << String::Format(u"\tIs heading:\t\t\t{0}", curStyle->get_IsHeading()) << std::endl;
std::cout << String::Format(u"\tIs QuickStyle:\t\t{0}", curStyle->get_IsQuickStyle()) << std::endl;
ASPOSE_ASSERT_EQ(doc, curStyle->get_Document());
}
}

◆ get_LinkedStyleName()

System::String Aspose::Words::Style::get_LinkedStyleName ( )

Gets the name of the Style linked to this one. Returns Empty string if no styles are linked.

Examples

Shows how to use style aliases.

auto doc = MakeObject<Document>(MyDir + u"Style with alias.docx");
// This document contains a style named "MyStyle,MyStyle Alias 1,MyStyle Alias 2".
// If a style's name has multiple values separated by commas, each clause is a separate alias.
SharedPtr<Style> style = doc->get_Styles()->idx_get(u"MyStyle");
ASPOSE_ASSERT_EQ(MakeArray<String>({u"MyStyle Alias 1", u"MyStyle Alias 2"}), style->get_Aliases());
ASSERT_EQ(u"Title", style->get_BaseStyleName());
ASSERT_EQ(u"MyStyle Char", style->get_LinkedStyleName());
// We can reference a style using its alias, as well as its name.
ASPOSE_ASSERT_EQ(doc->get_Styles()->idx_get(u"MyStyle Alias 1"), doc->get_Styles()->idx_get(u"MyStyle Alias 2"));
auto builder = MakeObject<DocumentBuilder>(doc);
builder->MoveToDocumentEnd();
builder->get_ParagraphFormat()->set_Style(doc->get_Styles()->idx_get(u"MyStyle Alias 1"));
builder->Writeln(u"Hello world!");
builder->get_ParagraphFormat()->set_Style(doc->get_Styles()->idx_get(u"MyStyle Alias 2"));
builder->Write(u"Hello again!");
ASPOSE_ASSERT_EQ(doc->get_FirstSection()->get_Body()->get_Paragraphs()->idx_get(0)->get_ParagraphFormat()->get_Style(),
doc->get_FirstSection()->get_Body()->get_Paragraphs()->idx_get(1)->get_ParagraphFormat()->get_Style());

◆ get_List()

System::SharedPtr<Aspose::Words::Lists::List> Aspose::Words::Style::get_List ( )

Gets the list that defines formatting of this list style.

This property is only valid for list styles. For other style types this property returns null.

Examples

Shows how to create a list style and use it in a document.

auto doc = MakeObject<Document>();
// A list allows us to organize and decorate sets of paragraphs with prefix symbols and indents.
// We can create nested lists by increasing the indent level.
// We can begin and end a list by using a document builder's "ListFormat" property.
// Each paragraph that we add between a list's start and the end will become an item in the list.
// We can contain an entire List object within a style.
SharedPtr<Style> listStyle = doc->get_Styles()->Add(StyleType::List, u"MyListStyle");
SharedPtr<List> list1 = listStyle->get_List();
ASSERT_TRUE(list1->get_IsListStyleDefinition());
ASSERT_FALSE(list1->get_IsListStyleReference());
ASSERT_TRUE(list1->get_IsMultiLevel());
ASPOSE_ASSERT_EQ(listStyle, list1->get_Style());
// Change the appearance of all list levels in our list.
for (const auto& level : list1->get_ListLevels())
{
level->get_Font()->set_Name(u"Verdana");
level->get_Font()->set_Color(System::Drawing::Color::get_Blue());
level->get_Font()->set_Bold(true);
}
auto builder = MakeObject<DocumentBuilder>(doc);
builder->Writeln(u"Using list style first time:");
// Create another list from a list within a style.
SharedPtr<List> list2 = doc->get_Lists()->Add(listStyle);
ASSERT_FALSE(list2->get_IsListStyleDefinition());
ASSERT_TRUE(list2->get_IsListStyleReference());
ASPOSE_ASSERT_EQ(listStyle, list2->get_Style());
// Add some list items that our list will format.
builder->get_ListFormat()->set_List(list2);
builder->Writeln(u"Item 1");
builder->Writeln(u"Item 2");
builder->get_ListFormat()->RemoveNumbers();
builder->Writeln(u"Using list style second time:");
// Create and apply another list based on the list style.
SharedPtr<List> list3 = doc->get_Lists()->Add(listStyle);
builder->get_ListFormat()->set_List(list3);
builder->Writeln(u"Item 1");
builder->Writeln(u"Item 2");
builder->get_ListFormat()->RemoveNumbers();
builder->get_Document()->Save(ArtifactsDir + u"Lists.CreateAndUseListStyle.docx");

◆ get_ListFormat()

System::SharedPtr<Aspose::Words::Lists::ListFormat> Aspose::Words::Style::get_ListFormat ( )

Provides access to the list formatting properties of a paragraph style.

This property is only valid for paragraph styles. For other style types this property returns null.

Examples

Shows how to create and use a paragraph style with list formatting.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Create a custom paragraph style.
SharedPtr<Style> style = doc->get_Styles()->Add(StyleType::Paragraph, u"MyStyle1");
style->get_Font()->set_Size(24);
style->get_Font()->set_Name(u"Verdana");
style->get_ParagraphFormat()->set_SpaceAfter(12);
// Create a list and make sure the paragraphs that use this style will use this list.
style->get_ListFormat()->set_List(doc->get_Lists()->Add(ListTemplate::BulletDefault));
style->get_ListFormat()->set_ListLevelNumber(0);
// Apply the paragraph style to the document builder's current paragraph, and then add some text.
builder->get_ParagraphFormat()->set_Style(style);
builder->Writeln(u"Hello World: MyStyle1, bulleted list.");
// Change the document builder's style to one that has no list formatting and write another paragraph.
builder->get_ParagraphFormat()->set_Style(doc->get_Styles()->idx_get(u"Normal"));
builder->Writeln(u"Hello World: Normal.");
builder->get_Document()->Save(ArtifactsDir + u"Styles.ParagraphStyleBulletedList.docx");

◆ get_Name()

System::String Aspose::Words::Style::get_Name ( ) const

Gets or sets the name of the style.

Can not be empty string.

If there already is a style with such name in the collection, then this style will override it. All affected nodes will reference new style.

Examples

Shows how to access a document's style collection.

auto doc = MakeObject<Document>();
ASSERT_EQ(4, doc->get_Styles()->get_Count());
// Enumerate and list all the styles that a document created using Aspose.Words contains by default.
{
SharedPtr<System::Collections::Generic::IEnumerator<SharedPtr<Style>>> stylesEnum = doc->get_Styles()->GetEnumerator();
while (stylesEnum->MoveNext())
{
SharedPtr<Style> curStyle = stylesEnum->get_Current();
std::cout << String::Format(u"Style name:\t\"{0}\", of type \"{1}\"", curStyle->get_Name(), curStyle->get_Type()) << std::endl;
std::cout << "\tSubsequent style:\t" << curStyle->get_NextParagraphStyleName() << std::endl;
std::cout << String::Format(u"\tIs heading:\t\t\t{0}", curStyle->get_IsHeading()) << std::endl;
std::cout << String::Format(u"\tIs QuickStyle:\t\t{0}", curStyle->get_IsQuickStyle()) << std::endl;
ASPOSE_ASSERT_EQ(doc, curStyle->get_Document());
}
}

Shows how to clone a document's style.

auto doc = MakeObject<Document>();
// The AddCopy method creates a copy of the specified style and
// automatically generates a new name for the style, such as "Heading 1_0".
SharedPtr<Style> newStyle = doc->get_Styles()->AddCopy(doc->get_Styles()->idx_get(u"Heading 1"));
// Use the style's "Name" property to change the style's identifying name.
newStyle->set_Name(u"My Heading 1");
// Our document now has two identical looking styles with different names.
// Changing settings of one of the styles do not affect the other.
newStyle->get_Font()->set_Color(System::Drawing::Color::get_Red());
ASSERT_EQ(u"My Heading 1", newStyle->get_Name());
ASSERT_EQ(u"Heading 1", doc->get_Styles()->idx_get(u"Heading 1")->get_Name());
ASSERT_EQ(doc->get_Styles()->idx_get(u"Heading 1")->get_Type(), newStyle->get_Type());
ASSERT_EQ(doc->get_Styles()->idx_get(u"Heading 1")->get_Font()->get_Name(), newStyle->get_Font()->get_Name());
ASPOSE_ASSERT_EQ(doc->get_Styles()->idx_get(u"Heading 1")->get_Font()->get_Size(), newStyle->get_Font()->get_Size());
ASPOSE_ASSERT_NE(doc->get_Styles()->idx_get(u"Heading 1")->get_Font()->get_Color(), newStyle->get_Font()->get_Color());

◆ get_NextParagraphStyleName()

System::String Aspose::Words::Style::get_NextParagraphStyleName ( )

Gets/sets the name of the style to be applied automatically to a new paragraph inserted after a paragraph formatted with the specified style.

Examples

Shows how to access a document's style collection.

auto doc = MakeObject<Document>();
ASSERT_EQ(4, doc->get_Styles()->get_Count());
// Enumerate and list all the styles that a document created using Aspose.Words contains by default.
{
SharedPtr<System::Collections::Generic::IEnumerator<SharedPtr<Style>>> stylesEnum = doc->get_Styles()->GetEnumerator();
while (stylesEnum->MoveNext())
{
SharedPtr<Style> curStyle = stylesEnum->get_Current();
std::cout << String::Format(u"Style name:\t\"{0}\", of type \"{1}\"", curStyle->get_Name(), curStyle->get_Type()) << std::endl;
std::cout << "\tSubsequent style:\t" << curStyle->get_NextParagraphStyleName() << std::endl;
std::cout << String::Format(u"\tIs heading:\t\t\t{0}", curStyle->get_IsHeading()) << std::endl;
std::cout << String::Format(u"\tIs QuickStyle:\t\t{0}", curStyle->get_IsQuickStyle()) << std::endl;
ASPOSE_ASSERT_EQ(doc, curStyle->get_Document());
}
}

◆ get_ParagraphFormat()

System::SharedPtr<Aspose::Words::ParagraphFormat> Aspose::Words::Style::get_ParagraphFormat ( )

Gets the paragraph formatting of the style.

For character and list styles this property returns null.

Examples

Shows how to create and use a paragraph style with list formatting.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Create a custom paragraph style.
SharedPtr<Style> style = doc->get_Styles()->Add(StyleType::Paragraph, u"MyStyle1");
style->get_Font()->set_Size(24);
style->get_Font()->set_Name(u"Verdana");
style->get_ParagraphFormat()->set_SpaceAfter(12);
// Create a list and make sure the paragraphs that use this style will use this list.
style->get_ListFormat()->set_List(doc->get_Lists()->Add(ListTemplate::BulletDefault));
style->get_ListFormat()->set_ListLevelNumber(0);
// Apply the paragraph style to the document builder's current paragraph, and then add some text.
builder->get_ParagraphFormat()->set_Style(style);
builder->Writeln(u"Hello World: MyStyle1, bulleted list.");
// Change the document builder's style to one that has no list formatting and write another paragraph.
builder->get_ParagraphFormat()->set_Style(doc->get_Styles()->idx_get(u"Normal"));
builder->Writeln(u"Hello World: Normal.");
builder->get_Document()->Save(ArtifactsDir + u"Styles.ParagraphStyleBulletedList.docx");

◆ get_StyleIdentifier()

Aspose::Words::StyleIdentifier Aspose::Words::Style::get_StyleIdentifier ( ) const

Gets the locale independent style identifier for a built-in style.

For user defined (custom) styles, this property returns User.

See also
Aspose::Words::Style::get_Name
Examples

Shows how to modify the position of the right tab stop in TOC related paragraphs.

auto doc = MakeObject<Document>(MyDir + u"Table of contents.docx");
// Iterate through all paragraphs with TOC result-based styles; this is any style between TOC and TOC9.
for (const auto& para : System::IterateOver(doc->GetChildNodes(NodeType::Paragraph, true)->LINQ_OfType<SharedPtr<Paragraph>>()))
{
if (para->get_ParagraphFormat()->get_Style()->get_StyleIdentifier() >= StyleIdentifier::Toc1 &&
para->get_ParagraphFormat()->get_Style()->get_StyleIdentifier() <= StyleIdentifier::Toc9)
{
// Get the first tab used in this paragraph, this should be the tab used to align the page numbers.
SharedPtr<TabStop> tab = para->get_ParagraphFormat()->get_TabStops()->idx_get(0);
// Replace the first default tab, stop with a custom tab stop.
para->get_ParagraphFormat()->get_TabStops()->RemoveByPosition(tab->get_Position());
para->get_ParagraphFormat()->get_TabStops()->Add(tab->get_Position() - 50, tab->get_Alignment(), tab->get_Leader());
}
}
doc->Save(ArtifactsDir + u"Styles.ChangeTocsTabStops.docx");

◆ get_Styles()

System::SharedPtr<Aspose::Words::StyleCollection> Aspose::Words::Style::get_Styles ( ) const

Gets the collection of styles this style belongs to.

Examples

Shows how to access a document's style collection.

auto doc = MakeObject<Document>();
ASSERT_EQ(4, doc->get_Styles()->get_Count());
// Enumerate and list all the styles that a document created using Aspose.Words contains by default.
{
SharedPtr<System::Collections::Generic::IEnumerator<SharedPtr<Style>>> stylesEnum = doc->get_Styles()->GetEnumerator();
while (stylesEnum->MoveNext())
{
SharedPtr<Style> curStyle = stylesEnum->get_Current();
std::cout << String::Format(u"Style name:\t\"{0}\", of type \"{1}\"", curStyle->get_Name(), curStyle->get_Type()) << std::endl;
std::cout << "\tSubsequent style:\t" << curStyle->get_NextParagraphStyleName() << std::endl;
std::cout << String::Format(u"\tIs heading:\t\t\t{0}", curStyle->get_IsHeading()) << std::endl;
std::cout << String::Format(u"\tIs QuickStyle:\t\t{0}", curStyle->get_IsQuickStyle()) << std::endl;
ASPOSE_ASSERT_EQ(doc, curStyle->get_Document());
}
}

◆ get_Type()

Aspose::Words::StyleType Aspose::Words::Style::get_Type ( ) const

Gets the style type (paragraph or character).

Examples

Shows how to access a document's style collection.

auto doc = MakeObject<Document>();
ASSERT_EQ(4, doc->get_Styles()->get_Count());
// Enumerate and list all the styles that a document created using Aspose.Words contains by default.
{
SharedPtr<System::Collections::Generic::IEnumerator<SharedPtr<Style>>> stylesEnum = doc->get_Styles()->GetEnumerator();
while (stylesEnum->MoveNext())
{
SharedPtr<Style> curStyle = stylesEnum->get_Current();
std::cout << String::Format(u"Style name:\t\"{0}\", of type \"{1}\"", curStyle->get_Name(), curStyle->get_Type()) << std::endl;
std::cout << "\tSubsequent style:\t" << curStyle->get_NextParagraphStyleName() << std::endl;
std::cout << String::Format(u"\tIs heading:\t\t\t{0}", curStyle->get_IsHeading()) << std::endl;
std::cout << String::Format(u"\tIs QuickStyle:\t\t{0}", curStyle->get_IsQuickStyle()) << std::endl;
ASPOSE_ASSERT_EQ(doc, curStyle->get_Document());
}
}

◆ GetType()

virtual const System::TypeInfo& Aspose::Words::Style::GetType ( ) const
overridevirtual

Reimplemented in Aspose::Words::TableStyle.

◆ Is()

virtual bool Aspose::Words::Style::Is ( const System::TypeInfo target) const
overridevirtual

Reimplemented in Aspose::Words::TableStyle.

◆ Remove()

void Aspose::Words::Style::Remove ( )

Removes the specified style from the document.

Style removal has following effects on the document model:

  • All references to the style are removed from corresponding paragraphs, runs and tables.
  • If base style is removed its formatting is moved to child styles.
  • If style to be deleted has a linked style, then both of these are deleted.
Examples

Shows how to create and apply a custom style.

auto doc = MakeObject<Document>();
SharedPtr<Style> style = doc->get_Styles()->Add(StyleType::Paragraph, u"MyStyle");
style->get_Font()->set_Name(u"Times New Roman");
style->get_Font()->set_Size(16);
style->get_Font()->set_Color(System::Drawing::Color::get_Navy());
auto builder = MakeObject<DocumentBuilder>(doc);
// Apply one of the styles from the document to the paragraph that the document builder is creating.
builder->get_ParagraphFormat()->set_Style(doc->get_Styles()->idx_get(u"MyStyle"));
builder->Writeln(u"Hello world!");
SharedPtr<Style> firstParagraphStyle = doc->get_FirstSection()->get_Body()->get_FirstParagraph()->get_ParagraphFormat()->get_Style();
ASPOSE_ASSERT_EQ(style, firstParagraphStyle);
// Remove our custom style from the document's styles collection.
doc->get_Styles()->idx_get(u"MyStyle")->Remove();
firstParagraphStyle = doc->get_FirstSection()->get_Body()->get_FirstParagraph()->get_ParagraphFormat()->get_Style();
// Any text that used a removed style reverts to the default formatting.
ASSERT_FALSE(doc->get_Styles()->LINQ_Any([](SharedPtr<Style> s) { return s->get_Name() == u"MyStyle"; }));
ASSERT_EQ(u"Times New Roman", firstParagraphStyle->get_Font()->get_Name());
ASPOSE_ASSERT_EQ(12.0, firstParagraphStyle->get_Font()->get_Size());
ASSERT_EQ(System::Drawing::Color::Empty.ToArgb(), firstParagraphStyle->get_Font()->get_Color().ToArgb());

◆ set_BaseStyleName()

void Aspose::Words::Style::set_BaseStyleName ( System::String  value)

◆ set_IsQuickStyle()

void Aspose::Words::Style::set_IsQuickStyle ( bool  value)

◆ set_Name()

void Aspose::Words::Style::set_Name ( System::String  value)

◆ set_NextParagraphStyleName()

void Aspose::Words::Style::set_NextParagraphStyleName ( System::String  value)

◆ Type()

static const System::TypeInfo& Aspose::Words::Style::Type ( )
static