Spire.Doc 支持从 word 文档中删除特定段落以及所有段落。本文详细介绍了如何使用 Spire.Doc 和 C# 从 Word 文档中删除段落。
我们使用的示例 word 文档:
Spire.Doc for.NET 最新下载(qun:767755948)https://www.evget.com/product/3368/download
删除特定段落
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); } } }
输出:
删除所有段落
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); } } }