C# 在分节符之间替换内容
我需要处理大量word文档,以便在两个分节符之间替换文档内容 文档的结构基本上如下所示: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
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。