如何在 OpenXML SDK 中拆分文档
我需要在 OpenXml sdk 2.0 中拆分文档。该文档包含多个部分,每个部分都有一个带有文本元素(部分名称)的页脚。有没有一种直接的方法可以从一个 OpenXml 文档复制到另一个文档?
I need to split a document in OpenXml sdk 2.0. The document has sections that each have a footer with a text element (name of the section). Is there a straightforward way to copy from one OpenXml document to another?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
DocumentBuilder 是您正在寻找的工具。例如,请参见
DocumentBuilder is the tool you are looking for. See for example, http://blogs.msdn.com/b/ericwhite/archive/2010/01/08/how-to-control-sections-when-using-openxml-powertools-documentbuilder.aspx
这将需要您做大量的工作来复制和合并样式表等。我建议使用 altChunk 来执行为您合并,因为它将为您处理所有困难的事情。这里有两个链接可以帮助解释更多:如何使用 altChunk 进行文档组装 和 如何:将多个文字处理文档组合到一个中
This would require a lot of work on your part to copy and merge stylesheets among other things. I'd recommend using altChunk to do the merging for you as it will take care of all the hard stuff for you. Here are two links to help explain it more: How to Use altChunk for Document Assembly and How to: Assemble Multiple Word Processing Documents in One
我仅使用 OpenXmlSDK 完成了与您所描述的类似的操作。尽管我不得不说这并不怎么有趣,而且我想要一个不需要自己雕刻的解决方案。就我而言,我必须保留页脚/页眉等与部分内容,并将文档拆分为几个其他文档。
当时,我找不到任何用于识别元素属于哪个部分的示例,因此必须自己编写一个实用程序。 (单词分割部分的方式是在内容之后注入分节符,并且 SDK 似乎没有提供任何帮助器。)然后,我必须使用 headerReference 找到标头定义并抓取在创建新文档并注入页眉、页脚和部分内容之前,也应包含该内容。
祝您好运!
I have done similar to what you describe using just the OpenXmlSDK. Though I have to say it wasn't much fun, and I was left wanting a solution I didn't have to carve myself. In my case I had to keep footers/headers etc. with section content and split the document into several other documents.
At the time I couldn't locate any samples on identifying which section an element belonged to, and had to write a utility myself. (The way word splits sections is by injecting a section break after the content, and the SDK didn't seem to provide any helpers.) I then had to locate the header definition by using the headerReference and grab that content too, before creating a new document and injecting the header, footer, and section content.
I wish you the best of luck!