我写了程序,要把word转化成html格式的文件,代码如下:
Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.ApplicationClass();
Type wordType = word.GetType();
Documents docs = word.Documents;
Type docsType = docs.GetType();
object fileName = "E:\\Acorn\\WESoft\\Media\\20080409橡果媒体改造讨论会笔记.doc";
Document doc = (Document)docsType.InvokeMember("Open",
System.Reflection.BindingFlags.InvokeMethod, null, docs, new Object[] {fileName, true, true});
// 转换格式,另存为
Type docType = doc.GetType();
string htmlName=DateTime.Now.ToString("yyyymmddHHmmss")+".html";
string savePath = Path.Combine(HttpRuntime.AppDomainAppPath,htmlName);
object saveFileName = savePath; docType.InvokeMember("SaveAs", System.Reflection.BindingFlags.InvokeMethod,
null, doc, new object[]{saveFileName, WdSaveFormat.wdFormatHTML});
//HidTempHtml.Value=s;
// 退出 Word
wordType.InvokeMember("Quit", System.Reflection.BindingFlags.InvokeMethod,
null, word, null);
但当执行到打开文档时,就过不去了,也不抛异常,就好像死这了,当我在进程中杀掉“WINWORD”时,才抛异常:
System.Runtime.InteropServices.COMException: 远程过程调用失败。
引用都加上了,DCOM的权限也设了,这是怎么回事呢,高手给帮忙看下
Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.ApplicationClass();
Type wordType = word.GetType();
Documents docs = word.Documents;
Type docsType = docs.GetType();
object fileName = "E:\\Acorn\\WESoft\\Media\\20080409橡果媒体改造讨论会笔记.doc";
Document doc = (Document)docsType.InvokeMember("Open",
System.Reflection.BindingFlags.InvokeMethod, null, docs, new Object[] {fileName, true, true});
// 转换格式,另存为
Type docType = doc.GetType();
string htmlName=DateTime.Now.ToString("yyyymmddHHmmss")+".html";
string savePath = Path.Combine(HttpRuntime.AppDomainAppPath,htmlName);
object saveFileName = savePath; docType.InvokeMember("SaveAs", System.Reflection.BindingFlags.InvokeMethod,
null, doc, new object[]{saveFileName, WdSaveFormat.wdFormatHTML});
//HidTempHtml.Value=s;
// 退出 Word
wordType.InvokeMember("Quit", System.Reflection.BindingFlags.InvokeMethod,
null, word, null);
但当执行到打开文档时,就过不去了,也不抛异常,就好像死这了,当我在进程中杀掉“WINWORD”时,才抛异常:
System.Runtime.InteropServices.COMException: 远程过程调用失败。
引用都加上了,DCOM的权限也设了,这是怎么回事呢,高手给帮忙看下
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货