Removing Style

Hi,


I am getting an additional paragraph style and wanted to know how to remove this style.


string blobtext = "";

foreach (Paragraph body in nodes)
{
if (body.Range.Text.Contains("1. OBJETIVO") == true)
{
Style newStyle = doc.Styles.AddCopy(doc.Styles["Heading 1"]);
newStyle.Name = "My Heading 1";
DocumentBuilder docbuilder = new DocumentBuilder(doc);
body.ParagraphFormat.Style = newStyle;
string text = string.Empty;
using (StreamReader streamReader = new StreamReader("C:\\Blob.htm", Encoding.UTF8))
{
text = streamReader.ReadToEnd();
}


blobtext = text;

DocumentBuilder builder = new DocumentBuilder(doc);

builder.MoveTo(body);

//Insert a Paragraph break
builder.InsertParagraph();

//Insert the Paragraph to repeat it
builder.InsertHtml(blobtext);


}
}

foreach (Paragraph body in nodes)
{
foreach (Run run in body.Runs)
{
if (run.Text == "")
{
body.ParagraphFormat.ClearFormatting();
}
}
}

//doc.Save(path);

thanks in advance




Hi James,


Thanks for your inquiry. You can remove the specified style from the document by using
the Style.Remove method. 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.

Moreover, please use Document.RemoveUnusedResources method if you want to remove unused styles and lists from the document.

Please let us know if you have any more queries.

Hi Tahir, thanks for your prompt response.
The following method worked for me.

builder.ParagraphFormat.ClearFormatting();

Hi James,


Thanks for your feedback. It is nice to hear from you that you have found the solution of your query. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.