Aspose::Words::BorderCollection::ClearFormatting method

BorderCollection::ClearFormatting method

Removes all borders of an object.

void Aspose::Words::BorderCollection::ClearFormatting()

Examples

Shows how to remove all borders from all paragraphs in a document.

auto doc = System::MakeObject<Aspose::Words::Document>(System::String(get_MyDir() + u"Borders.docx"));

// The first paragraph of this document has visible borders with these settings.
System::SharedPtr<Aspose::Words::BorderCollection> firstParagraphBorders = doc->get_FirstSection()->get_Body()->get_FirstParagraph()->get_ParagraphFormat()->get_Borders();

ASSERT_EQ(firstParagraphBorders->get_Color().ToArgb(), System::Drawing::Color::get_Red().ToArgb());
ASSERT_EQ(firstParagraphBorders->get_LineStyle(), LineStyle::Single);
ASPOSE_ASSERT_EQ(firstParagraphBorders->get_LineWidth(), 3.0);

// Use the "ClearFormatting" method on each paragraph to remove all borders.
for (auto&& paragraph : System::IterateOver<Aspose::Words::Paragraph>(doc->get_FirstSection()->get_Body()->get_Paragraphs()))
{
    paragraph->get_ParagraphFormat()->get_Borders()->ClearFormatting();

    for (auto&& border : System::IterateOver(paragraph->get_ParagraphFormat()->get_Borders()))
    {
        ASSERT_EQ(border->get_Color().ToArgb(), System::Drawing::Color::Empty.ToArgb());
        ASSERT_EQ(border->get_LineStyle(), LineStyle::None);
        ASPOSE_ASSERT_EQ(border->get_LineWidth(), 0.0);
    }
}

doc->Save(get_ArtifactsDir() + u"BorderCollection.RemoveAllBorders.docx");

See Also