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

查看:20
本文介绍了如何使用字节流形成 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天全站免登陆