合并文档

发布于 2024-08-25 03:57:43 字数 169 浏览 8 评论 0原文

我正在尝试使用 OpenXML SDK 2.0 将两个 docx 文档合并为一个 docx 文档。应合并文档,而不会丢失其样式以及自定义页眉和页脚。我希望我可以使用 AltChunk 和分节符来实现这一点。但我无法让它工作。

我想做的事情可能吗?有人可以给我提示如何实现这一目标吗?

I'm trying to merge two docx-documents into one docx-document using OpenXML SDK 2.0. The documents should be merged without loosing their styling and custom headers and footers. I hope I can achieve this using AltChunk and a section break. But I can't get it working.

Is it possible what I'm trying to do? Can someone give me a hint how to achieve this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

岁吢 2024-09-01 03:57:43

上面的答案根本不正确!这正是 AltChunk 的设计目的,而且效果非常好!

注意:在 Word 第一次打开文件之前,这些文档不会合并为一个文档(显然必须保存该文件,否则磁盘上的文件不会更新。)

请参阅此博客以获取有关如何合并的更多信息正确地做:
https://blogs.msdn.com/b/ericwhite/archive/2008/10/27/how-to-use-altchunk-for-document- assembly.aspx?Redirected=true

ps 作为对于使用生产力工具检查 Open XML,我的意见是只需安装官方的 Visual Studio Open XML 插件并从 Visual Studio 打开 Office 文档即可检查它们,超级方便! :-)

The above answer is NOT correct at all! This is EXACTLY what AltChunk has been designed to do, and it works great!

NOTE: that the documents will not be merged into one document UNTIL Word opens the file for the first time (obviously the file has to be saved or the file on disk won't be updated.)

See this blog for more information on how to do it properly:
https://blogs.msdn.com/b/ericwhite/archive/2008/10/27/how-to-use-altchunk-for-document-assembly.aspx?Redirected=true

p.s. As for examining Open XML using the productivity tool, my opinion is to just install the official Visual Studio Open XML add-on and open the Office Documents from Visual Studio to examine them, it's super convenient! :-)

深爱不及久伴 2024-09-01 03:57:43

我使用“Open XML Productivity Tool”分析了 docx 文档的结构,并得出结论,使用 Altchunk 将文档与其样式、页眉、页脚等合并是不可能的。 。您可以从 打开 xml sdk

我现在正在做的、正在起作用的是将所有内容手动复制到文档中,确保保留所有样式引用、页眉引用、页脚引用……。这意味着我先给它们一个新的唯一 ID,然后再将它们复制到文档中并将所有引用从旧 ID 更改为新 ID。有很多代码可以做到这一点,但上面提到的工具确实很有帮助。

添加分节符也相当困难。您应该知道 SectionProperties< /a>-tag 描述该节的所有属性,并且 Body-tag 下可以有一个 SectionProperties-tag,描述最后一个节的属性。因此,添加新的分节符意味着将最后一个 SectionProperties 标记复制到该节的最后一段,并在 BodySectionProperties 标记>-标签。我还从生产力工具中获得了很多信息。

Using the 'Open XML Productivity Tool' I analyzed the structure of a docx-document, and concluded that merging documents with their style, headers, footers, ... is not possible out of the box using Altchunk. You can download the tool seperatly from the open xml sdk.

What I'm doing now, and what is working, is copying everything manually into to document, making sure that all style-references, header-references, footer-references, ... are preserved. This means that I give them a new unique id before I copy them into the document and changing all references from the old id to the new id. There is a lot of code to do this, but the tool mentioned above really helped.

Adding a section break is also quite difficult. You should know that the SectionProperties-tag describes all the properties of the section and that there can be one SectionProperties-tag under the Body-tag, describing the properties of the last section. So adding a new sectionbreak, means copying the last SectionProperties-tag to the last paragraph of the section and adding a new SectionProperties-tag under the Body-tag. I also got al lot of information from the productivity tool.

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