Word控件Spire.Doc 【段落处理】教程(十八):在 C# 中从 Word 文档中删除段落

发布于:2022-12-19 ⋅ 阅读:(313) ⋅ 点赞:(0)

Spire.Doc 支持从 word 文档中删除特定段落以及所有段落。本文详细介绍了如何使用 Spire.Doc 和 C# 从 Word 文档中删除段落。

我们使用的示例 word 文档:

Spire.Doc for.NET 最新下载(qun:767755948)icon-default.png?t=M85Bhttps://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);

}
}
}


网站公告

今日签到

点亮在社区的每一天
去签到