从剪贴板获取Word ML [英] Get Word ML from clipboard

查看:127
本文介绍了从剪贴板获取Word ML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在拦截Richtextbox的粘贴事件,以便在粘贴之前处理内容.如果它包含表格或图像等,我需要做一些自定义的事情.如果复制的选择来自Word 2010,并且包含混合内容(例如,文本和表格/图像),则Word将内容以多种格式放置在剪贴板上.这些包括HTML和RTF,但我宁愿使用WordML.我已经使用ClipSpy来检查剪贴板上实际放置了哪些格式和数据,并且嵌入源"格式似乎是包含WordML的格式.我认为可以将其作为一个包打开:

I am intercepting the paste event for a richtextbox, in order to process the contents before pasting. If it contains tables or images etc. I need to do some custom stuff. If the copied selection is from Word 2010 and consists of mixed content (eg. text and table/image) Word places the content on the clipboard in a number of formats. These includes HTML and RTF, but I would rather work with WordML. I've used ClipSpy to check what formats and data is actually put on the clipboard and the "Embed source" format seems to be the format containing WordML. I would think this could be opened as a Package:

var stream = Clipboard.GetData("Embed Source") as MemoryStream;
var package = Package.Open(stream);

它抛出一个EndOfStreamException,并且我认为它会被包裹在其他东西中.我可以将流写入磁盘并使用7-zip打开它,然后看内容是否如预期的那样. 所以基本上有两个问题: 嵌入源"是获取WordML的正确DataObject吗? 如果是,该如何反序列化?

It throws an EndOfStreamException and I'm thinking it migth be wrapped in something else. I can write the stream to disk and open it using 7-zip and see that the contents are as expected. So basically two questions: Is "Embed source" the right DataObject to get the WordML? If it is, how do I deserialize it?

推荐答案

将流保存到磁盘并与适当的docx进行二进制比较后,我发现它实际上包装在复合文档文件中: http://www.openoffice.org/sc/compdocfileformat.pdf .我用谷歌搜索了前几个字节

After saving the stream to disk and doing a binary comparison to a proper docx, I figured out that it was in fact wrapped in a Compound Document File: http://www.openoffice.org/sc/compdocfileformat.pdf. I googled the first few bytes

D0 CF 11 E0 A1 B1 1A E1

这是CDF格式的标识符.

which is the identifier of the CDF format.

可以使用OpenMCDF从化合物文件中提取软件包.

The package can be extracted from the Compound file using OpenMCDF.

这篇关于从剪贴板获取Word ML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆