DsWord allows you to add, modify, and delete a paragraph from a Word document. It allows you to add a paragraph to the paragraph collection using Add method of the ParagraphCollection class, modify it using the Paragraphs property which accesses the paragraph collection, and delete it using the Delete method of the ContentObject class.
To add a paragraph to a document:
C# |
Copy Code |
---|---|
//Add first paragraph doc.Body.Sections.First.GetRange().Paragraphs.Add("Hello, World!"); //Add another paragraph doc.Body.Sections.First.GetRange().Paragraphs.Add("Document Solutions"); //Save the document doc.Save("AddParagraph.docx"); |
To modify a paragraph in a document:
C# |
Copy Code |
---|---|
doc.Load("AddParagraph.docx"); //Modify settings of the first paragraph doc.Body.Sections.First.GetRange().Paragraphs.First.Format.Alignment = ParagraphAlignment.Center; //Save the document doc.Save("ModifyParagraph.docx"); |
To delete a paragraph from a document, access a paragraph from the paragraph collection using the Paragraphs property and delete it using Delete method of the ContentObject class.
C# |
Copy Code |
---|---|
doc.Load("AddParagraph.docx"); //Delete the last paragraph doc.Body.Sections.First.GetRange().Paragraphs.Last.Delete(); //Save the document doc.Save("DeleteParagraph.docx"); |
For more information on how to work with paragraphs using DsWord, see DsWord sample browser.