2011-02-07 72 views
2

我想通过使用C#和Open XML SDK以编程方式拆分Word文档。我们已经按照段落分割了Word文档。现在我们要为每个部分执行相同的操作。请任何有这方面知识的人善意告诉我解决这个问题。如何使用C#和Open XML SDK按部分分割Word文档?

+2

嗨,你能显示你用来分段的代码吗? – 2011-02-07 11:53:25

回答

6

了解应用部分的位置有点古怪。而不是将章节包装在章节中,这样可以使我们更容易识别,而是将章节应用于之前发现的所有内容。

在段落的ParagraphProperties中查找SectionProperties元素,这些是定义Section断开的内容。当您找到SectionProperties定义时,最后一个SectionProperties定义和此新定义之间的所有内容将作为一个部分组合在一起。 例如考虑以下因素:

Paragraph1 // Section 1 

Paragraph2 // Section 1 

SectionProperties (Section 1) // Defines what section 1 is like 

Paragraph3 // Section 2 

Paragraph4 // Section 2 

SectionProperties (Section 2) // Defines what section 2 is like 

Paragraph5 // Section 3 

Final SectionProperties // Defines what Section 3 is like. 
// This final definition exists within the Body tag itself. 
// Other SectionProperties exist under Paragraph Properties 

还记得最后SectionProperties没有在段落中生活,它坐落在body标签中的根级别。不幸的是,据我所知,SDK不提供用于计算段落属于哪个段的快捷方式。从这里你应该可以得到一个计算部分的快速系统。