有人通过下面这种方法将word转为html,private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
Word.ApplicationClass word = new Word.ApplicationClass();
Type wordType = word.GetType();
Word.Documents docs = word.Documents; // 打开文件
Type docsType = docs.GetType();
object fileName = "d:\\tmp\\aaa.doc";
Word.Document doc = (Word.Document)docsType.InvokeMember("Open",
System.Reflection.BindingFlags.InvokeMethod, null, docs, new Object[] {fileName, true, true});
// 转换格式,另存为
Type docType = doc.GetType();
object saveFileName = "d:\\tmp\\aaa.html";
//下面是Microsoft Word 9 Object Library的写法,如果是10,可能写成:
//docType.InvokeMember("SaveAs", System.Reflection.BindingFlags.InvokeMethod,
null, doc, new object[]{saveFileName, Word.WdSaveFormat.wdFormatFilteredHTML});
///其它格式:
///wdFormatHTML
///wdFormatDocument
///wdFormatDOSText
///wdFormatDOSTextLineBreaks
///wdFormatEncodedText
///wdFormatRTF
///wdFormatTemplate
///wdFormatText
///wdFormatTextLineBreaks
///wdFormatUnicodeText
docType.InvokeMember("SaveAs", System.Reflection.BindingFlags.InvokeMethod,
null, doc, new object[]{saveFileName, Word.WdSaveFormat.wdFormatHTML}); // 退出 Word
wordType.InvokeMember("Quit", System.Reflection.BindingFlags.InvokeMethod,
null, word, null);
}现在我想取出已转换为html文件的文本内容,要如何实现?请大家帮忙,谢谢
{
// 在此处放置用户代码以初始化页面
Word.ApplicationClass word = new Word.ApplicationClass();
Type wordType = word.GetType();
Word.Documents docs = word.Documents; // 打开文件
Type docsType = docs.GetType();
object fileName = "d:\\tmp\\aaa.doc";
Word.Document doc = (Word.Document)docsType.InvokeMember("Open",
System.Reflection.BindingFlags.InvokeMethod, null, docs, new Object[] {fileName, true, true});
// 转换格式,另存为
Type docType = doc.GetType();
object saveFileName = "d:\\tmp\\aaa.html";
//下面是Microsoft Word 9 Object Library的写法,如果是10,可能写成:
//docType.InvokeMember("SaveAs", System.Reflection.BindingFlags.InvokeMethod,
null, doc, new object[]{saveFileName, Word.WdSaveFormat.wdFormatFilteredHTML});
///其它格式:
///wdFormatHTML
///wdFormatDocument
///wdFormatDOSText
///wdFormatDOSTextLineBreaks
///wdFormatEncodedText
///wdFormatRTF
///wdFormatTemplate
///wdFormatText
///wdFormatTextLineBreaks
///wdFormatUnicodeText
docType.InvokeMember("SaveAs", System.Reflection.BindingFlags.InvokeMethod,
null, doc, new object[]{saveFileName, Word.WdSaveFormat.wdFormatHTML}); // 退出 Word
wordType.InvokeMember("Quit", System.Reflection.BindingFlags.InvokeMethod,
null, word, null);
}现在我想取出已转换为html文件的文本内容,要如何实现?请大家帮忙,谢谢
解决方案 »
- 请大家帮我看看如何优化!分不多大家帮帮忙
- byte[] 数据存入 Sqlserver数据库 Image类型字段 取出数据 与存入的不一样
- Silverlight 异步传输数据问题
- 数据库里存在某条数据,现在要根据某一字段把这条数据里的所有值写入combx里,该怎么写代码呢????
- NickLee.FortuneJava(2007.2) for Vs.net2005 SP1、mainsoft、Java、Linux
- 请问各位大虾, checkbox的用法
- 关于监控硬盘 只需提示一下即可!
- 求C#发邮件的代码。。
- 拼了!!!只要能够答出来的而且运行通过的,答对一个给一个分,最少20分!无上限!
- 用C#如何实现对sqlserver或msde创建数据库? 在线等待!
- 通过一个DataAdapter对象能不能把两个Excel表的数据,取到一个DataSet中?
- 怎么显示水晶报表中的每组分页的页码
{
// 在此处放置用户代码以初始化页面
Word.ApplicationClass word = new Word.ApplicationClass();
Type wordType = word.GetType();
Word.Documents docs = word.Documents; // 打开文件
Type docsType = docs.GetType();
object fileName = "d:\\tmp\\aaa.doc";
Word.Document doc = (Word.Document)docsType.InvokeMember("Open",
System.Reflection.BindingFlags.InvokeMethod, null, docs, new Object[] {fileName, true, true});
// 转换格式,另存为
Type docType = doc.GetType();
object saveFileName = "d:\\tmp\\aaa.html"; //<-这里已经有了保存路径
docType.InvokeMember("SaveAs", System.Reflection.BindingFlags.InvokeMethod,
null, doc, new object[]{saveFileName, Word.WdSaveFormat.wdFormatHTML}); // 退出 Word
wordType.InvokeMember("Quit", System.Reflection.BindingFlags.InvokeMethod,
null, word, null);
//读取已经保存的文件
Sysetem.IO.StreamReader sr = new StreamReader(saveFileName.ToString(),
Encoding.Default);
string strHtml = sr.ReadToEnd();//<-strHtml中就是Html的文本了。
sr.Close();}