狂送分(100):关于使用Microsoft.Office.Interop.Word.ApplicationClass的问题
MIZYY 2007-03-14 01:55:01 我的程序需要实现一个功能:将服务器中的word文档转化成html格式的文件。
程序中引用了com组件:Microsoft Office 11.0;Microsoft Word 11.0 Object Library两个组件
相应代码如下:
Microsoft.Office.Interop.Word.ApplicationClass word = new Microsoft.Office.Interop.Word.ApplicationClass();
Type wordType = word.GetType();
Microsoft.Office.Interop.Word.Documents docs = word.Documents;
// 打开文件
Type docsType = docs.GetType();
object fileName = "d:\\tmp\\aaa.doc";
Microsoft.Office.Interop.Word.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 = "d:\\tmp\\aaa.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);
//垃圾回收
GC.Collect();
GC.WaitForPendingFinalizers();
权限设置如下:
1.我已经将DCOM配置中的Microsoft word文档的属性中身份验证级别设为无;加入了应有的用户权限(SYSTEM;INTERACTIVE;Everyone;Administrators;IUSR_<machinename>;IWAM_<machinename>);运行该程序的帐户也选择了交互式用户
2.文件夹的权限也都是读写都可以
操作系统是:Windows 2003
经过测试结果如下:
如果我没有安装Windows2003的补丁,则程序运行正常,功能可以实现;
如果我安装Windows2003的补丁以后,程序则不能执行,系统报错,错误信息为:“因为配置类型不正确,系统无法开始服务器进程。请检查用户名和密码。”
各位高手,有哪位也遇到过这样的情况,能否给于指教,多谢了!!