编辑存储在数据库中的Word文件 [英] Editing Word files stored in a Database

查看:141
本文介绍了编辑存储在数据库中的Word文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们希望将Microsoft Word模板存储在我们的数据库中。然后,我们希望允许用户编辑模板文件,然后将它们存储回数据库中。在这种情况下使用的最佳策略是什么?

We want to store Microsoft Word templates in our database. Then we wish to allow the user to edit the template files and then store them back to the database. What is the best strategy to use in this situation?

如果我们让Word在单独的进程中运行,是否有可能?即不在我们的应用程序中托管。如果是这样,这将涉及监视磁盘上的文件是否有更改,因为这听起来很可怕。考虑到这一点,我们希望从内存流中打开文件,并且永远不要让它接触磁盘。

Is this possible if we have Word running in a separate process? i.e. not hosted in our application. If so would this involve monitoring a file on disk for changes, as that sounds horrible. With this thinking we would like to open the file from a memory stream and never let it touch the disk. But we are open to suggestions.

将其写入磁盘的问题可能是:

The problem with writing it to disk could be:

一旦打开单词用户从临时文件或文件夹中创建了一个新文档而未保存,然后没有关闭word。 (因此我们无法确定进程何时完成)或删除了临时文件或文件夹。我想要一个我可以控制字词的解决方案,或者将其托管在应用程序中。我不想将其写入文件。有什么想法吗?

Once word opened from a temp file or folder the user created a new document without saving, then did not close word. (so we couldn't tell when the process finished) Or deleted the temp file or folder. i would like the solution where i could control word, perhaps host it in app. i would like to not have to write it to a file. any ideas?

推荐答案

要进行编辑,我将文件下载到temp文件夹中,然后在您的应用程序中使用自动化功能启动Word :

For editing, I would download file into temp folder, and then in your application I will launch Word using Automation:

Application app = new Application();
app.Visible = true;
Document doc = app.Documents.Open("path to temp file");

这些行将启动Word并打开文件。
然后,您可以监视文档和Word实例发生了什么,并且当用户保存它时,只需将文件上传回数据库即可。

These lines will launch Word and open your file. Then, you can monitor what is happening to your document and Word instance, and when the user saves it, just upload the file back to the database.

您始终可以通过执行以下行来隐藏和/或关闭该实例:

You can always hide and/or close this instance by executing following lines:

app.Visible = false;
app.Quit();

请注意,您必须引用 Microsoft.Office.Interop.Word 程序集

这篇关于编辑存储在数据库中的Word文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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