| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1687 人关注过本帖
标题:[求助]读取word文档内容?
只看楼主 加入收藏
lilyguaiguai
Rank: 1
等 级:新手上路
帖 子:33
专家分:0
注 册:2006-12-9
收藏
 问题点数:0 回复次数:9 
[求助]读取word文档内容?
用DirectoryInfo可以找到文档所在的路径,如何读取.doc的内容并显示在页面上?
先谢了
搜索更多相关主题的帖子: 文档 word doc 路径 
2007-07-31 17:37
冰彩虹
Rank: 4
来 自:上海
等 级:贵宾
威 望:14
帖 子:806
专家分:44
注 册:2007-6-28
收藏
得分:0 
找找帖子,好像有相关的内容

Flying without wings
2007-07-31 18:07
lilyguaiguai
Rank: 1
等 级:新手上路
帖 子:33
专家分:0
注 册:2006-12-9
收藏
得分:0 
多谢
我找一下

2007-08-01 10:17
lilyguaiguai
Rank: 1
等 级:新手上路
帖 子:33
专家分:0
注 册:2006-12-9
收藏
得分:0 
[求助]谁有做过WORD转HTML的 http://bbs.bc-cn.net/viewthread.php?tid=153428&star=at240161#240161这个帖子吗?
可惜没有人解答哟

2007-08-01 10:20
冰彩虹
Rank: 4
来 自:上海
等 级:贵宾
威 望:14
帖 子:806
专家分:44
注 册:2007-6-28
收藏
得分:0 

哈,没做过也

试试...


Flying without wings
2007-08-01 10:26
冰彩虹
Rank: 4
来 自:上海
等 级:贵宾
威 望:14
帖 子:806
专家分:44
注 册:2007-6-28
收藏
得分:0 

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

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组件的引用


Flying without wings
2007-08-01 10:47
lilyguaiguai
Rank: 1
等 级:新手上路
帖 子:33
专家分:0
注 册:2006-12-9
收藏
得分:0 

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


2007-08-02 10:53
冰彩虹
Rank: 4
来 自:上海
等 级:贵宾
威 望:14
帖 子:806
专家分:44
注 册:2007-6-28
收藏
得分:0 

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


Flying without wings
2007-08-02 12:11
liubaoqiang
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2007-7-12
收藏
得分:0 


TargetInvocationException: 调用的目标发生了异常
2007-08-07 16:16
liubaoqiang
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2007-7-12
收藏
得分:0 

无法打开宏储存。
说明: 执行当前 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

2007-08-07 16:17
快速回复:[求助]读取word文档内容?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014037 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved