如何使用 C# 和 Open XML SDK 按部分拆分 Word 文档?

发布于 2024-10-15 23:58:13 字数 107 浏览 5 评论 0原文

我想使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

擦肩而过的背影 2024-10-22 23:58:13

知道这些部分的应用位置有点奇怪。章节不是将段落包含在章节中(这将使我们更容易识别),而是适用于在它们之前找到的所有内容。

在段落的 ParagraphProperties 中查找 SectionProperties 元素,这些元素定义了分节符。当您找到一个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 没有提供计算段落所属部分的快捷方式。从这里您应该能够获得一个用于计算截面的快速系统。

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:

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文