Aspose::Words::CleanupOptions::get_DuplicateStyle method
Contents
[
Hide
]CleanupOptions::get_DuplicateStyle method
Gets/sets a flag indicating whether duplicate styles should be removed from document. Default value is false.
bool Aspose::Words::CleanupOptions::get_DuplicateStyle() const
Examples
Shows how to remove duplicated styles from the document.
auto doc = MakeObject<Document>();
// Add two styles to the document with identical properties,
// but different names. The second style is considered a duplicate of the first.
SharedPtr<Style> myStyle = doc->get_Styles()->Add(StyleType::Paragraph, u"MyStyle1");
myStyle->get_Font()->set_Size(14);
myStyle->get_Font()->set_Name(u"Courier New");
myStyle->get_Font()->set_Color(System::Drawing::Color::get_Blue());
SharedPtr<Style> duplicateStyle = doc->get_Styles()->Add(StyleType::Paragraph, u"MyStyle2");
duplicateStyle->get_Font()->set_Size(14);
duplicateStyle->get_Font()->set_Name(u"Courier New");
duplicateStyle->get_Font()->set_Color(System::Drawing::Color::get_Blue());
ASSERT_EQ(6, doc->get_Styles()->get_Count());
// Apply both styles to different paragraphs within the document.
auto builder = MakeObject<DocumentBuilder>(doc);
builder->get_ParagraphFormat()->set_StyleName(myStyle->get_Name());
builder->Writeln(u"Hello world!");
builder->get_ParagraphFormat()->set_StyleName(duplicateStyle->get_Name());
builder->Writeln(u"Hello again!");
SharedPtr<ParagraphCollection> paragraphs = doc->get_FirstSection()->get_Body()->get_Paragraphs();
ASPOSE_ASSERT_EQ(myStyle, paragraphs->idx_get(0)->get_ParagraphFormat()->get_Style());
ASPOSE_ASSERT_EQ(duplicateStyle, paragraphs->idx_get(1)->get_ParagraphFormat()->get_Style());
// Configure a CleanOptions object, then call the Cleanup method to substitute all duplicate styles
// with the original and remove the duplicates from the document.
auto cleanupOptions = MakeObject<CleanupOptions>();
cleanupOptions->set_DuplicateStyle(true);
doc->Cleanup(cleanupOptions);
ASSERT_EQ(5, doc->get_Styles()->get_Count());
ASPOSE_ASSERT_EQ(myStyle, paragraphs->idx_get(0)->get_ParagraphFormat()->get_Style());
ASPOSE_ASSERT_EQ(myStyle, paragraphs->idx_get(1)->get_ParagraphFormat()->get_Style());
See Also
- Class CleanupOptions
- Namespace Aspose::Words
- Library Aspose.Words for C++