簡體   English   中英

如何將Interop.Word.Document對象轉換為流或字節數組?

[英]How to convert an Interop.Word.Document object to a stream or byte array?

我正在嘗試將我在內存中創建的Word文檔上載到Sharepoint 2010,看來這樣做的唯一方法是將其轉換為字節數組或流。 無論如何,我無需先將其保存到磁盤即可執行此操作?

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

建議正確的方法是

  • 將文檔復制到剪貼板,然后從剪貼板流式傳輸數據,或者...
  • 閱讀文檔Range的XML。

將文檔轉換為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/zh-CN/84f1ac3f-f078-4087-a627-351d6bb57173/how-to-get-document-content-in-byte-array?forum=vsto

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM