通过先保存文件,再读磁盘方式。此处非另存为,也不需要改变WORD中现有文件的路径。
var document = Globals.ThisAddIn.Application.ActiveDocument;
var ipersistfile = (System.Runtime.InteropServices.ComTypes.IPersistFile) document;
string tempfile = Path.GetTempFileName();
ipersistfile.Save(tempfile, false);
using(var stream = File.Open(tempfile, FileMode.Open, FileAccess.Read, FileShare.Read)) {
//do something with the stream
}

本文介绍了一种Word文档的临时保存与读取方法,通过将活动文档保存到临时文件中并打开此文件进行后续操作的方式实现。该方法不需要改变文档原始路径,适用于需要对文档内容进行临时处理的场景。

546

被折叠的 条评论
为什么被折叠?



