gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 14:02:56 24 4
gpt4 key购买 nike

我想使用 C# 和 Open XML SDK 以编程方式按部分拆分 Word 文档。我们已经按段落拆分了 Word 文档。现在我们要对每个部分进行相同的操作。请在这方面有知识的任何人让我知道如何解决这个问题。

最佳答案

了解这些部分的应用位置有点古怪。不是将段落包裹在节中,这将使我们更容易识别,而是将节应用于在它们之前找到的所有内容。

在段落的 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 不提供计算段落所属部分的快捷方式。从这里您应该能够获得一个用于计算截面的快速系统。

关于c# - 如何使用 C# 和 Open XML SDK 按部分拆分 Word 文档?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4920532/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com