从 Office 2007 加载项序列化当前的 ActiveDocument [英] Serialize current ActiveDocument from office 2007 add-in

查看:23
本文介绍了从 Office 2007 加载项序列化当前的 ActiveDocument的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建 VSTO Office 2007 加载项.

Im creating a VSTO Office 2007 add-in.

我需要启用或找到一种解决方案,以便我可以使用 byte[] 而不是硬盘驱动器保存到网络服务.

I need to be enable or find a solution where I can save to a webservice with a byte[] instead of hard drive.

所以,我通过转到网站并单击 URL 来打开文档,然后单击向我发送 Word 文档,然后选择使用 MS Word 2007 打开.

So, I open the document by going to a website and clicking on a url, that click send me a Word Document, and I select Open using MS Word 2007.

文档已打开,如果我检查了我拥有的数据:

The document open, and if I check the data I have:

ActiveDocument.Fullname = http://[servername or ip]/[某些 iis 文件夹]/file.asp?id=353&type=doc`

ActiveDocument.Fullname = http://[servername or ip]/[some iis folder]/file.asp?id=353&type=doc`

所以我认为这一切都在内存中,因为我没有原始文件或临时文件(如果存在).

so I think this is all in memory since I dont have the original file or temp file if exists.

我的磁盘没有问题,即使文档是打开的.如何从当前的 ActiveDocument 执行 byte[] ?

I have no problem from a disk, even if the document is open. How can I do a byte[] from an current ActiveDocument?

我找到了很多答案,都说它无法完成.但我也有一个客户有一个旧的加载项,它从当前的 ActiveDocument 中执行 byte[].

I have found a lot of answers, that state that it cannot be done. But I also have a customer that have an old add-in that does the byte[] from a current ActiveDocument.

谁能帮帮我.

推荐答案

您可以转换 ActiveDocument 到 COM 互操作 IPersistFile 将打开的文档字节的副本保存到本地临时路径和然后将它们读回以发送到您的网络服务.在 Office 中,如果不先保存到磁盘,就无法从活动文档中读取字节.请参阅 此 MSDN 博客供参考.

COM.IPersistFile compoundDocument = Application.ActiveDocument as COM.IPersistFile; 
compoundDocument.Save(filePath, false);
byte[] content = File.ReadAllBytes(filePath);

这篇关于从 Office 2007 加载项序列化当前的 ActiveDocument的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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