【问题标题】:How to convert an Interop.Word.Document object to a stream or byte array?如何将 Interop.Word.Document 对象转换为流或字节数组?
【发布时间】:2014-12-16 20:42:04
【问题描述】:

我正在尝试将我在内存中创建的 Word 文档上传到 Sharepoint 2010,看起来这样做的唯一方法是将其转换为字节数组或流。无论如何我可以先将其保存到磁盘吗?

【问题讨论】:

    标签: c# .net office-interop


    【解决方案1】:

    此链接:http://social.msdn.microsoft.com/forums/en-US/vsto/thread/84f1ac3f-f078-4087-a627-351d6bb57173/

    建议正确的方法是要么

    • 将文档复制到剪贴板,然后从剪贴板流式传输数据,或者...
    • 读取文档 Range 的 XML。

    【讨论】:

      【解决方案2】:

      将文档投射到IPersistFile接口,然后简单的执行“Save(path,false)”方法:

      var iPersistFile = (IPersistFile)this.Application.ActiveDocument;
      iPersistFile.Save("[path]",false);
      

      所有功劳归于这些人:

      http://blogs.msdn.com/b/pranavwagh/archive/2008/04/03/how-to-do-a-save-copy-as-in-word.aspx

      https://social.msdn.microsoft.com/Forums/vstudio/en-US/84f1ac3f-f078-4087-a627-351d6bb57173/how-to-get-document-content-in-byte-array?forum=vsto

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-09-19
        • 1970-01-01
        • 2014-11-08
        • 2018-09-08
        • 2021-11-30
        • 2015-08-05
        • 2019-09-02
        • 1970-01-01
        相关资源
        最近更新 更多