Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在分节符之间替换内容_C#_Ms Word_Openxml - Fatal编程技术网

C# 在分节符之间替换内容

C# 在分节符之间替换内容,c#,ms-word,openxml,C#,Ms Word,Openxml,我需要处理大量word文档,以便在两个分节符之间替换文档内容 文档的结构基本上如下所示: Content ========= Continuous Section Break ========== Content with 2 columns ========= Continuous Section Break ========== Content 我已经知道如何检测文档中的中断 using (WordprocessingDocument myDoc = WordprocessingD

我需要处理大量word文档,以便在两个分节符之间替换文档内容

文档的结构基本上如下所示:

Content    
========= Continuous Section Break ==========
Content with 2 columns
========= Continuous Section Break ==========
Content
我已经知道如何检测文档中的中断

using (WordprocessingDocument myDoc = WordprocessingDocument.Open(filename, true)) 

{ 

MainDocumentPart mainPart = myDoc.MainDocumentPart; 

List<Break> breaks = mainPart.Document.Descendants<Break>().ToList(); 

// TODO replace content between the breaks 

mainPart.Document.Save(); 

} 
使用(WordprocessingDocument myDoc=WordprocessingDocument.Open(filename,true))
{ 
MainDocumentPart mainPart=myDoc.MainDocumentPart;
列表分隔符=mainPart.Document.subjects().ToList();
//TODO在中断之间替换内容
mainPart.Document.Save();
} 
但我不知道如何替换它们之间的内容


非常感谢您的帮助。

我使用本文中介绍的OpenXML Power Tools解决了我的问题。

在MS Word中,您可以找到
节集合
,它允许分别对每个节进行操作<代码>部分具有
.Range属性
,该属性表示文本范围。试试这些技巧。@KazJaw谢谢,但我使用的是开放式XML SDK,不是VBA。