转换互操作对象的Word中的byte []不保存体力 [英] Convert Word of interop object to byte [] without saving physically

查看:119
本文介绍了转换互操作对象的Word中的byte []不保存体力的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的 Microsoft.Office.Interop Microsoft.Office.Word 并与所有创建,段落,表格之类的在内存中创建一个对象。我需要这个对象生成一个内容字节[]喂养在一个表中的相同类型的一个领域。
,我不能将其保存在任何物理,以便使用一个FileStream,解决我的问题oDoc.Save(路径)的问题。

I have an object created in memory using Microsoft.Office.Interop and Microsoft.Office.Word and with all created, paragraphs, tables and the like. I need this object to generate a content byte [] to feed one field of the same type in a table. The problem that I can not save it in any way physically with a oDoc.Save ("path") in order to use a FileStream and solve my problem.

尝试了好几种解决方案,以及如何使用剪贴板,并没有工作。任何解决方案?

Have tried several solutions and how to use the clipboard, and did not work. Any solution?

推荐答案

你真的要使用 Microsoft.Office.Interop Microsoft.Office.Word

如果它是不是真的有必要,你可以使用< A HREF =http://www.microsoft.com/download/en/details.aspx?id=5124相对=nofollow> OpenXML的SDK库了解操纵WordDocument的内容。

If it is not really necessary, you could use the OpenXML SDK libraries for manipulating the content of the WordDocument.

OpenXML的SDK中包含一个类 WordprocessingDocument ,可以操纵包含内容WordDocument内存流。和的MemoryStream 可以使用转换 ToArray的()字节[]

OpenXML SDK contains a class WordprocessingDocument that can manipulate a memory stream containing a WordDocument content. And MemoryStream can be converted using ToArray() to a byte[].

作为一个代码示例:

byte[] templateContent = File.ReadAllBytes(templateFile);

MemoryStream stream = new MemoryStream();
stream.Write(templateContent, 0, templateContent.Length);

WordprocessingDocument wordDoc = WordprocessingDocument.Open(stream, true);

// When done
byte[] contentOfWordFile = stream.toArray();

这篇关于转换互操作对象的Word中的byte []不保存体力的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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