先谢了
先谢了
找的资料,试过了可以,楼主试试看吧
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组件的引用
无法打开宏储存。
说明: 执行当前 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