文檔半島外圍網上直營>>E-iceblue中文文檔>>在文檔中刪除分頁符
                在文檔中刪除分頁符
在 Word 文檔中,用戶可以添加新的分頁符或刪除現有的分頁符。此示例顯示如何使用 Spire.Doc 從 word 文檔中刪除分頁符。Spire.Doc支持從.docx、.doc、RTF等格式的word文檔中去除分頁符。
技術交流Q群(767755948)
首先確保Spire.Doc for .NET已正確安裝,然后通過以下路徑在下載的 Bin 文件夾中添加 Spire.Doc.dll 作為參考:“.. \Spire.Doc\Bin\NET4.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 document
for (int j = 0; j < document.Sections[0].Paragraphs.Count; j++)
{
Paragraph p = document.Sections[0].Paragraphs[j];
// Traverse every child object of a paragraph
for (int i = 0; i < p.ChildObjects.Count; i++)
{
DocumentObject obj = p.ChildObjects[i];
//Find the page break object
if (obj.DocumentObjectType == DocumentObjectType.Break)
{
Break b = obj as Break;
// Remove the page break object from paragraph
p.ChildObjects.Remove(b);
//save the document to file.
document.SaveToFile("result.docx");
請查看有效截圖:
	 
 
完整代碼:
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");
}
}
}
 
                
            
 QQ交談
QQ交談 在線咨詢
在線咨詢 
                 
                
 渝公網安備
            50010702500608號
渝公網安備
            50010702500608號
             
            
 客服熱線
客服熱線