如何使用字节流形成Word文档 [英] How can I form a Word document using stream of bytes

查看:177
本文介绍了如何使用字节流形成Word文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个字节流,实际上(如果放正确)将形成一个有效的Word文件,我需要将此流转换为Word文件而不将其写入磁盘,我从SQL Server数据库表中获取原始流:

I have a stream of bytes which actually (if put right) will form a valid Word file, I need to convert this stream into a Word file without writing it to disk, I take the original stream from SQL Server database table:

ID   Name    FileData
----------------------------------------
1    Word1   292jf2jf2ofm29fj29fj29fj29f2jf29efj29fj2f9 (actual file data)

FileData字段携带数据.

the FileData field carries the data.

Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application();
Microsoft.Office.Interop.Word.Document doc = new Microsoft.Office.Interop.Word.Document(); 
doc = word.Documents.Open(@"C:\SampleText.doc");
doc.Activate();

上面的代码打开并从文件系统填充Word文件,我不想要,我想定义一个新的Microsoft.Office.Interop.Word.Document,但是我想从字节流中手动填充其内容.

The above code opens and fill a Word file from File System, I don't want that, I want to define a new Microsoft.Office.Interop.Word.Document, but I want to fill its content manually from byte stream.

获取内存中的Word文档后,我想对关键字进行一些解析.

After getting the in-memory Word document, I want to do some parsing of keywords.

有什么想法吗?

推荐答案

  1. 创建一个内存文件系统,有相应的驱动程序.
  2. 给出一个指向ftp服务器路径(或其他)的路径,然后您可以使用该路径来推送数据.

需要注意的重要一件事:将文件存储在数据库中通常不是一个好的设计.

One important thing to note: storing files in a database is generally not good design.

这篇关于如何使用字节流形成Word文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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