OpenXML 内容控制
我想知道是否有人可以提供帮助。我的文档中包含多个内容控件。每个内容控件包含列表或有时包含样式的单个段落。
根据某些登录,我想复制整个内容控件或内容控件的内容并将其粘贴到另一个文档中。
简而言之,是否有一种方法可以使用 OpenXML 在保留样式的文档之间复制和粘贴内容控件?
任何帮助都将受到高度赞赏。
提前致谢。
阿什温
I am wondering if someone can help. I have document with several content controls within it. Each content control contains lists or sometime single parapgraphs with styling.
Depending upon certain login I want to copy the entire content control or the content of the content control and paste it into another document.
In short, is there a way to copy and paste content controls between documents preserving styles using OpenXML?
Any help with be highly appreciated.
Thanks in advance.
Ashwin
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
OpenXML 基本上是 XML DOM 的集合(就像底层 DOCX 文件是包含一堆 XML 文件的 zip 文件一样)。因此,它不是该术语通常含义的复制/粘贴。
您可以从一个 OpenXML 复制节点(及其子节点)以插入/添加到另一个 OpenXML。但这并不一定简单。例如,如果复制的节点中有一个段落的样式在目标 OpenXML 中不存在,则您还需要复制该样式的节点(及其子节点)。对于字体、列表等也是如此。
对于具有简单内容的内容控件(样式/字体未设置或两者都不存在),这非常简单。但有些情况你错过了,那些你需要解决的情况。我知道这不是最具体的帮助,但您必须处理的内容很大程度上取决于您的内容控制中的内容。例如,如果其中有一个位图,那么该位图(OpenXML 中的一个不同对象)也必须被复制。
OpenXML is basically a collection of XML DOMs (just as the underlying DOCX file is a zip file containing a bunch of XML files). So it's not copy/paste as the term is generally meant.
You can copy a node (and its children) from one OpenXML to insert/add to the other. But it is not necessarily simple. For example, if the copied node has a paragraph with a style that does not exist in the destination OpenXML, you need to copy that style's node (and children) too. Same for fonts, lists, etc.
For content controls with simple content (styles/fonts not set or exist in both), this is pretty easy. But the cases where there's something you missed, those you need to address. I know this is not the most specific help, but what you have to handle is highly dependent on what is in your content control. For example, if you have a bitmap in one, then the bitmap, which is a distinct object in the OpenXML, also has to be copied.