【问题标题】:Serialize current ActiveDocument from office 2007 add-in从 office 2007 加载项序列化当前 ActiveDocument
【发布时间】:2012-08-29 09:55:43
【问题描述】:

我正在创建一个 VSTO Office 2007 加载项。

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

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

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

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

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

我从磁盘上没有问题,即使文件是打开的。 我怎样才能从当前的ActiveDocument 做一个byte[]

我找到了很多答案,表明它无法完成。但我也有一个客户有一个旧插件,它从当前的 ActiveDocument 执行 byte[]

谁能帮帮我。

【问题讨论】:

    标签: ms-word vsto ms-office office-addins


    【解决方案1】:

    您可以将ActiveDocument 转换为COM 互操作IPersistFile 以将打开文档的字节副本保存到本地临时路径,然后将它们读回以发送到您的网络服务。在 Office 中,如果不先保存到磁盘,就无法从活动文档中读取字节。见this MSDN blog for reference

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

    【讨论】:

    • 我已经实现了你的代码。它可以工作:) 但 ActiveDocument 是否持有属性和 BuildInProperties。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-29
    相关资源
    最近更新 更多