Word控件Spire.Doc 【页面设置】教程(5) 如何在 C# 中删除分页符

本文主要向大家介绍如何在 C# 中删除分页符,欢迎查阅!

在 Word 文档中,用户可以添加新的分页符或删除现有的分页符。此示例显示如何使用 Spire.Doc 从 word 文档中删除分页符。Spire.Doc支持从.docx、.doc、RTF等格式的word文档中去除分页符。

首先确保Spire.Doc for .NET已正确安装,然后通过以下路径在下载的 Bin 文件夹中添加 Spire.Doc.dll 作为参考:“.. Spire.DocBinNET4.0 Spire.Doc .dll”。以下是如何在 C# 中删除分页符的详细信息。

//Create a new word document and load from the file.Document document = new Document();document.LoadFromFile("sample.docx");// Traverse every paragraph of the first section of the documentfor (int j = 0; j < document.Sections[0].Paragraphs.Count; j++){Paragraph p = document.Sections[0].Paragraphs[j];// Traverse every child object of a paragraphfor (int i = 0; i < p.ChildObjects.Count; i++){DocumentObject obj = p.ChildObjects[i];//Find the page break objectif (obj.DocumentObjectType == DocumentObjectType.Break){Break b = obj as Break;// Remove the page break object from paragraphp.ChildObjects.Remove(b);//save the document to file.document.SaveToFile("result.docx");

请查看有效截图

如何在 C# 中删除分页符

完整代码

using Spire.Doc;using Spire.Doc.Documents;namespace RemovePageBreak{class Program{static void Main(string[] args){Document document = new Document();document.LoadFromFile("sample.docx", FileFormat.Docx);for (int j = 0; j < document.Sections[0].Paragraphs.Count; j++){Paragraph p = document.Sections[0].Paragraphs[j];for (int i = 0; i < p.ChildObjects.Count; i++){DocumentObject obj = p.ChildObjects[i];if (obj.DocumentObjectType == DocumentObjectType.Break){Break b = obj as Break;p.ChildObjects.Remove(b);}}}document.SaveToFile("result.docx", FileFormat.Docx);System.Diagnostics.Process.Start("result.docx");}}}

欢迎下载|体验更多E-iceblue产品

获取更多信息请咨询在线客服  


标签:

来源:慧都

声明:本站部分文章及图片转载于互联网,内容版权归原作者所有,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2022年5月11日
下一篇 2022年5月11日

相关推荐

发表回复

登录后才能评论