检索 COM 类工厂中 CLSID 为 {000209FF-0000-0000-C000-000000000046} 的组件时失败,原因是出现以下错误: 80070005
在CSDN上总是有网友问这个问题,自己也遇到过,因些写出来供参考:
症状:
oWordApplic = New Word.Application
当程序运行到这句时出现下面的错误:
检索 COM 类工厂中 CLSID 为 {000209FF-0000-0000-C000-000000000046} 的组件时失败,原因是出现以下错误: 80070005。
oWordApplic = New Word.Application
当程序运行到这句时出现下面的错误:
检索 COM 类工厂中 CLSID 为 {000209FF-0000-0000-C000-000000000046} 的组件时失败,原因是出现以下错误: 80070005。
解决方法一:
控制面板-》管理工具-》组件服务-》计算机-》我的电脑-》DCom配置-》找到Microsoft Word文档
之后
单击属性打开此应用程序的属性对话框。
2. 单击标识选项卡,然后选择交互式用户。
3.单击"安全"选项卡,分别在"启动和激活权限"和"访问权限"组中选中"自定义",然后
自定义->编辑->添加ASP.NET账户和IUSER_计算机名
* 这些帐户仅在计算机上安装有 IIS 的情况下才存在。
13. 确保允许每个用户访问,然后单击确定。
14. 单击确定关闭 DCOMCNFG。
解决方法二:
如果上述方法不能解决问题,就应该是权限问题,请尝试用下面的方法:
在web.config中使用身份模拟,在<system.web>节中加入 <identity impersonate="true" userName="你的用户名" password="密码"/>
</system.web>
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Microsoft.Office.Interop.Excel;
using System.Diagnostics;
public partial class Default3 : System.Web.UI.Page
{
protected DateTime process_AfterTime;
protected void Page_Load(object sender, EventArgs e)
{
ApplicationClass excel = new ApplicationClass();
excel.Application.Workbooks.Add(true);
excel.Cells[1, 1] = "单元名称";
excel.Cells[1, 2] = "指标及其描述、特征值和权重";
excel.Cells[1, 23] = "属性";
excel.Cells[2, 2] = "D";
excel.Cells[2, 5] = "R";
excel.Cells[2, 8] = "A";
excel.Cells[2, 11] = "S";
excel.Cells[2, 14] = "T";
excel.Cells[2, 17] = "I";
excel.Cells[2, 20] = "C";
excel.Cells[2, 23] = "结果";
excel.Cells[2, 24] = "等级";
excel.Cells[3, 2] = "描述";
excel.Cells[3, 3] = "特征值";
excel.Cells[3, 4] = "权重";
excel.Cells[3, 5] = "描述";
excel.Cells[3, 6] = "特征值";
excel.Cells[3, 7] = "权重";
excel.Cells[3, 8] = "描述";
excel.Cells[3, 9] = "特征值";
excel.Cells[3, 10] = "权重";
excel.Cells[3, 11] = "描述";
excel.Cells[3, 12] = "特征值";
excel.Cells[3, 13] = "权重";
excel.Cells[3, 14] = "描述";
excel.Cells[3, 15] = "特征值";
excel.Cells[3, 16] = "权重";
excel.Cells[3, 17] = "描述";
excel.Cells[3, 18] = "特征值";
excel.Cells[3, 19] = "权重";
excel.Cells[3, 20] = "描述";
excel.Cells[3, 21] = "特征值";
excel.Cells[3, 22] = "权重";
excel.get_Range(excel.Cells[1, 1], excel.Cells[3, 1]).MergeCells = true;
excel.get_Range(excel.Cells[1, 2], excel.Cells[1, 22]).MergeCells = true;
excel.get_Range(excel.Cells[1, 23], excel.Cells[1, 24]).MergeCells = true;
excel.get_Range(excel.Cells[2, 2], excel.Cells[2, 4]).MergeCells = true;
excel.get_Range(excel.Cells[2, 5], excel.Cells[2, 7]).MergeCells = true;
excel.get_Range(excel.Cells[2, 8], excel.Cells[2, 10]).MergeCells = true;
excel.get_Range(excel.Cells[2, 11], excel.Cells[2, 13]).MergeCells = true;
excel.get_Range(excel.Cells[2, 14], excel.Cells[2, 16]).MergeCells = true;
excel.get_Range(excel.Cells[2, 17], excel.Cells[2, 19]).MergeCells = true;
excel.get_Range(excel.Cells[2, 20], excel.Cells[2, 22]).MergeCells = true;
excel.get_Range(excel.Cells[2, 23], excel.Cells[3, 23]).MergeCells = true;
excel.get_Range(excel.Cells[2, 24], excel.Cells[3, 24]).MergeCells = true;
excel.Visible = false;
excel.DisplayAlerts = false;
excel.Save(Server.MapPath("~/Storage/1.xls"));
excel.Application.Workbooks.Close();
excel.Application.Quit();
excel.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(excel);
process_AfterTime = DateTime.Now;
KillProcess();
GC.Collect();
}
private void KillProcess()
{
foreach (Process pro in Process.GetProcessesByName("EXCEL"))
{
DateTime processBeginTime = pro.StartTime;
if ((processBeginTime <= process_AfterTime))
pro.Kill();
}
}
}