注册 登录
编程论坛 ASP.NET技术论坛

[求助]读取word文档内容?

lilyguaiguai 发布于 2007-07-31 17:37, 1692 次点击
用DirectoryInfo可以找到文档所在的路径,如何读取.doc的内容并显示在页面上?
先谢了
9 回复
#2
冰彩虹2007-07-31 18:07
找找帖子,好像有相关的内容
#3
lilyguaiguai2007-08-01 10:17
多谢
我找一下
#4
lilyguaiguai2007-08-01 10:20
[求助]谁有做过WORD转HTML的 https://bbs.bc-cn.net/viewthread.php?tid=153428&star=at240161#240161这个帖子吗?
可惜没有人解答哟
#5
冰彩虹2007-08-01 10:26

哈,没做过也

试试...

#6
冰彩虹2007-08-01 10:47

找的资料,试过了可以,楼主试试看吧

ApplicationClass word = new ApplicationClass();
Type wordType = word.GetType();
Documents docs = word.Documents;

//打开文件
Type docsType = docs.GetType();
object fileName = "f:\\resume.doc";
Document doc = (Microsoft.Office.Interop.Word.Document)docsType.InvokeMember("Open", System.Reflection.BindingFlags.InvokeMethod, null, docs, new Object[] { fileName, true, true });

//转换格式,另存为
Type docType = doc.GetType();
object saveFileName = "f:\\resume.html";
docType.InvokeMember("SaveAs", System.Reflection.BindingFlags.InvokeMethod, null, doc, new object[] { saveFileName, Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatHTML });

//退出Word
wordType.InvokeMember("Quit", System.Reflection.BindingFlags.InvokeMethod, null, word, null);

PS:记得添加Word组件的引用

#7
lilyguaiguai2007-08-02 10:53

提示:
命名空间“Microsoft.Office”中不存在类型或命名空间名称“Interop”(是缺少程序集引用吗?)
怎么回事呀?

#8
冰彩虹2007-08-02 12:11

是要添加Word组件的引用的哈

#9
liubaoqiang2007-08-07 16:16


TargetInvocationException: 调用的目标发生了异常
#10
liubaoqiang2007-08-07 16:17

无法打开宏储存。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。

异常详细信息: System.Runtime.InteropServices.COMException: 无法打开宏储存。

源错误:


行 37: Type docsType = docs.GetType();
行 38: //object fileName = "f:\\resume.doc";
行 39: Document doc = (Microsoft.Office.Interop.Word.Document)docsType.InvokeMember("Open", System.Reflection.BindingFlags.InvokeMethod, null, docs, new Object[] { fileName, true, true });
行 40:
行 41: //Document oWordDoc = word.Documents.Open(ref fileName, ref missing, ref readOnly

1