XIAO牛
----在雨中长大

检索 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>

需添加引用,选择COM-->选择Microsoft   Excel   10.0   Object   Library组件
using System;
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[
11= "单元名称";
        excel.Cells[
12= "指标及其描述、特征值和权重";
        excel.Cells[
123= "属性";
        excel.Cells[
22= "D";
        excel.Cells[
25= "R";
        excel.Cells[
28= "A";
        excel.Cells[
211= "S";
        excel.Cells[
214= "T";
        excel.Cells[
217= "I";
        excel.Cells[
220= "C";
        excel.Cells[
223= "结果";
        excel.Cells[
224= "等级";
        excel.Cells[
32= "描述";
        excel.Cells[
33= "特征值";
        excel.Cells[
34= "权重";
        excel.Cells[
35= "描述";
        excel.Cells[
36= "特征值";
        excel.Cells[
37= "权重";
        excel.Cells[
38= "描述";
        excel.Cells[
39= "特征值";
        excel.Cells[
310= "权重";
        excel.Cells[
311= "描述";
        excel.Cells[
312= "特征值";
        excel.Cells[
313= "权重";
        excel.Cells[
314= "描述";
        excel.Cells[
315= "特征值";
        excel.Cells[
316= "权重";
        excel.Cells[
317= "描述";
        excel.Cells[
318= "特征值";
        excel.Cells[
319= "权重";
        excel.Cells[
320= "描述";
        excel.Cells[
321= "特征值";
        excel.Cells[
322= "权重";
        excel.get_Range(excel.Cells[
11], excel.Cells[31]).MergeCells = true;
        excel.get_Range(excel.Cells[
12], excel.Cells[122]).MergeCells = true;
        excel.get_Range(excel.Cells[
123], excel.Cells[124]).MergeCells = true;
        excel.get_Range(excel.Cells[
22], excel.Cells[24]).MergeCells = true;
        excel.get_Range(excel.Cells[
25], excel.Cells[27]).MergeCells = true;
        excel.get_Range(excel.Cells[
28], excel.Cells[210]).MergeCells = true;
        excel.get_Range(excel.Cells[
211], excel.Cells[213]).MergeCells = true;
        excel.get_Range(excel.Cells[
214], excel.Cells[216]).MergeCells = true;
        excel.get_Range(excel.Cells[
217], excel.Cells[219]).MergeCells = true;
        excel.get_Range(excel.Cells[
220], excel.Cells[222]).MergeCells = true;
        excel.get_Range(excel.Cells[
223], excel.Cells[323]).MergeCells = true;
        excel.get_Range(excel.Cells[
224], excel.Cells[324]).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();
        }
    }

}
posted on 2008-07-04 17:29  XIAO牛  阅读(2565)  评论(0编辑  收藏  举报