如何使用 C# 和 Open XML SDK 按部分拆分 Word 文档?
我想使用 C# 和 Open XML SDK 以编程方式按节拆分 Word 文档。我们已经按段落拆分了 Word 文档。现在我们要对每个部分执行相同的操作。请任何有这方面知识的人告诉我来解决这个问题。
I want to split a Word document by section programatically using C# and the Open XML SDK. We already we split the Word document by paragraph. Now we want to do the same operation for each section. Please anybody having knowledge in this area kindly let me know to resolve this problem.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
知道这些部分的应用位置有点奇怪。章节不是将段落包含在章节中(这将使我们更容易识别),而是适用于在它们之前找到的所有内容。
在段落的 ParagraphProperties 中查找 SectionProperties 元素,这些元素定义了分节符。当您找到一个SectionProperties 定义时,最后一个SectionProperties 定义和这个新定义之间的所有内容都将组合在一起作为一个部分。
例如,请考虑以下情况:
还请记住,最后一个SectionProperties 并不位于段落中,它位于Body 标记内的根级别。不幸的是,据我所知,SDK 没有提供计算段落所属部分的快捷方式。从这里您应该能够获得一个用于计算截面的快速系统。
Knowing where the sections are applied is a little quirky. Rather than wrapping paragraphs within sections, which would make it easy for us to identify, sections instead apply to all the content found before them.
Look for SectionProperties elements within the ParagraphProperties of a paragraph, these are what define Section breaks. When you find a SectionProperties definition, all content between the last SectionProperties definition and this new definition is grouped together as a section.
For example consider the following:
Also remember that the last SectionProperties doesn't live within a paragraph, it sits at the root level inside the Body tag. Unfortunately as far as I know the SDK doesn't provide shortcuts for calculating which section a Paragraph belongs to. From here you should be able to get a quick system for calculating sections.