admin 管理员组

文章数量: 887017

我想在文档的末尾添加一个分节符并添加一些文本.

我的代码如下:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using DocumentFormat.OpenXml.Packaging;

using DocumentFormat.OpenXml.Wordprocessing;

namespace WordDocManipulation

{

class Program

{

static void Main(string[] args)

{

string path = @"C:\sample.docx";

string strtxt = "Hello This is done by programmatically";

OpenAndAddTextToWordDocument(path,strtxt);

}

public static void OpenAndAddTextToWordDocument(string filepath,string txt)

{

/* I want to the below text to be added in the new section */

// Open a WordprocessingDocument for editing using the filepath.

WordprocessingDocument wordprocessingDocument =

WordprocessingDocument.Open(filepath,true);

// Assign a reference to the existing document body.

Body body = wordprocessingDocument.MainDocumentPart.Document.Body;

// Add new text.

Paragraph para = body.AppendChild(new Paragraph());

Run run = para.AppendChild(new Run());

run.AppendChild(new Text(txt));

// Close the handle explicitly.

wordprocessingDocument.Close();

}

}

}

我该怎么办?

本文标签: 下一页 分界 如何使用 php openxml