将 WPF UI 对象嵌入到 Word/OpenOffice 文档中?
我正在开发一个需要将自定义对象嵌入到文档(Microsoft Word 或 OpenOffice Writer)中的项目。这些对象本质上类似于 Microsoft 方程或 OpenOffice 公式对象,只不过它们会呈现并允许编辑特定于我们业务的内容。最终,文档将导出为 PDF。
由于该项目中的其他所有内容都基于 WPF,并且我们的开发环境和构建过程基于 .Net,因此如果能够完全或几乎完全使用 WPF/.Net 创建这些对象,那就太好了。
将对象嵌入到文档中最明显的选择是 OLE,但据我所知,WPF 对 OLE 的支持很少。
我有什么选择?什么是最好的(可靠的、高性能的、简单的)?
(或者,如果有人确定除了使用 C++ 或 VB6 等语言进行 OLE 之外没有其他好方法,那么知道这一点也很好)
I'm working on a project which needs to embed custom objects into documents (either Microsoft Word or OpenOffice Writer). The objects would essentially be like Microsoft Equation or OpenOffice Formula objects, except they would render and allow editing of content specific to our business. Ultimately, the documents are exported into PDF.
Since everything else in this project is based on WPF and our development environments and build processes are based on .Net, it would be nice to be able to create these objects using exclusively or almost exclusively WPF/.Net.
The most obvious choice for embedding objects into documents is OLE, but as far as I can tell, WPF has very little support for OLE.
What options do I have? What's the best (reliable, performant, and simple) do this?
(Or if anyone knows for sure that there isn't a good way other than going to OLE with a language like C++ or VB6, that would be good to know too)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在 WPF
RichTextBox
中执行此操作,只需插入一个InlineUIContainer
(或BlockUIContainer
),其中可以放置任何UIElement
比如按钮或者任何更复杂的东西。然后,您可以使用 OpenXML SDK 将
RichTextBox
内容(原来是FlowDocument
)转换为 RTF、XAML 或 HTML,或者转换为 Office OpenXML 格式 (.docx)。也许可以将
RichTexBox
替换为实际的 Microsoft Word 窗口,卡在 WPF 应用程序中,并在其中嵌入 WPF 控件,就像使用InlineUIContainer
一样,但我还不知道怎么办。如果我发现的话我会发帖的。You can do that inside a WPF
RichTextBox
, just insert anInlineUIContainer
(orBlockUIContainer
) where can put anyUIElement
like a button or anything more complicated.You can then convert the
RichTextBox
content, orginally aFlowDocument
, into RTF or XAML or HTML, or to the Office OpenXML format (.docx) with the OpenXML SDK.Maybe it's possible to replace the
RichTexBox
with an actual Microsoft Word window, stuck inside your WPF application, and embed WPF controls in it just like you do with aInlineUIContainer
, but I don't know how yet. I'll post if I find out.