Spire.Doc supports to remove a specific paragraph along with all of the paragraphs from a word document. This article elaborates how we can remove paragraphs from a word document using Spire.Doc and C#.
The example word document we used:
Remove a specific paragraph
using Spire.Doc; namespace RemoveParagh { class Program { static void Main(string[] args) { //Instantiate a Document object Document document = new Document(); //Load the Word document document.LoadFromFile("Input.docx"); //Remove the first paragraph from the first section of the document document.Sections[0].Paragraphs.RemoveAt(0); //Save the document document.SaveToFile("RemoveParagraph.docx", FileFormat.Docx2013); } } }
Output:
Remove all of the paragraphs
using Spire.Doc; namespace RemoveParagh { class Program { static void Main(string[] args) { //Instantiate a Document object Document document = new Document(); //Load the Word document document.LoadFromFile("Input.docx"); //Remove paragraphs from every section in the document foreach (Section section in document.Sections) { section.Paragraphs.Clear(); } //Save the document document.SaveToFile("RemoveAllParagraphs.docx", FileFormat.Docx2013); } } }
Output: