Do you remember how miserable you write paper with an unfamiliar topic? At first, you write and then delete what you write and then rewrite what you deleted one second ago. Actually, no matter what we write, we will modify to make it more attractive after completing. When editing, some existing paragraphs will be removed and some new will be added. In this post, I will show a method about how to remove paragraphs in Word document with C#, VB .NET.
At beginning, we need some materials: word template with several paragraphs and a .NET Word component, Spire.Doc for .NET to realize this function very easily and quickly. (P.S The following screenshot presents part of Word template contents)
Next, follow steps to use the tool to delete one or more paragraphs in this Word template.
- Load this Word template.
- Get paragraphs in specified section of document. Use ParagraphCollection.RemoveAt method provided by Spire.Doc for .NET and pass paragraph index overload to this method to remove specified paragraphs.
- Save the edited document with a new name.
Ensure that Spire.Doc has been downloaded and installed on your system and the dll has been added as reference in your project. Then, you can follow the code blow to realize the function to delete Word paragraphs.
static void Main(string args)
Document document = new Document();
//Remove Paragraph 2
//Remove Paragraph 3
//Save and Launch
Friend Class watermark
Shared Sub Main(ByVal args() As String)
Dim document As New Document()
‘Remove Paragraph 2
‘Remove Paragraph 3
‘Save and Launch
After running, we can find that paragraph 2 and 3 has been removed as screenshot shown blow.