读.doc文件,而无需启动的MSWord [英] Reading .doc file without launching MSWord

查看:187
本文介绍了读.doc文件,而无需启动的MSWord的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想打开.doc文件并阅读其内容。但我无法找到任何方式如何做到这一点,而无需启动的MSWord。

I'm trying to open .doc file and read its content. But i can't find any way how to do this without launching MSWord.

现在我有以下code:

Now I have following code:

Microsoft.Office.Interop.Word.Application app = new Microsoft.Office.Interop.Word.Application();
object nullObject = System.Reflection.Missing.Value;
object file = @"C:\doc.doc";
Microsoft.Office.Interop.Word.Document doc = app.Documents.Open(ref file, ref nullObject, ref nullObject,
         ref nullObject, ref nullObject, ref nullObject, ref nullObject, ref nullObject, ref nullObject,
         ref nullObject, ref nullObject, ref nullObject, ref nullObject, ref nullObject, ref nullObject,
         ref nullObject);
doc.ActiveWindow.Selection.WholeStory();
doc.ActiveWindow.Selection.Copy();
IDataObject data = Clipboard.GetDataObject();
string text = data.GetData(DataFormats.Text).ToString();
doc.Close(ref nullObject, ref nullObject, ref nullObject);
app.Quit(ref nullObject, ref nullObject, ref nullObject);

但它推出的MSWord,任何解决办法做到这一点,而无需启动?

But it launches MSWord, any solution to do it without launching?

推荐答案

两种可能性:要么使用的微软的规格编写您自己的解析器为.doc格式,或者使用一个现有的库为目的(例如,从的 的Aspose)。除非你有几个备用的年花的任务,后者显然是正确的选择。

Two possibilities: either use Microsoft's spec to write your own parser for the .doc format, or use an existing library for the purpose (e.g., from Aspose). Unless you have a couple of spare years to spend on the task, the latter is clearly the correct choice.

这篇关于读.doc文件,而无需启动的MSWord的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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