开发者

Error in excel = new Microsoft.Office.Interop.Excel.ApplicationClass();" when hosted in server machine..[dcomcnfg]

The following is the code which thows error when hosted in Server PC.

try
{
    //Variable Declarations
    Microsoft.Office.Interop.Excel._Workbook oWB;
    Microsoft.Office.Interop.Excel.Application oXL = null;

    Microsoft.Office.Interop.Excel.Workbook workbook;
    Microsoft.Office.Interop.Excel.Worksheet NwSheet = null;
    Microsoft.Office.Interop.Excel.Worksheet NwSheetSummary;
    Microsoft.Office.Interop.Excel.Worksheet NwSheetIndividualTotal;
    Microsoft.Office.Interop.Excel.Range ShtRange;
    Microsoft.Office.Interop.Excel.Sheets sheets;

    Microsoft.Office.Interop.Excel.ApplicationClass excel = new Microsoft.Office.Interop.Excel.ApplicationClass();

    excel.Workbooks.Add(System.Reflection.Missing.Value);

    excel.Quit();
    excel = null;

    //Opening Excel file(myData.xlsx)
    workbook = excel.Workbooks.Open(System.Web.HttpContext.Current.Server.MapPath("~/Template/Template.xlsx"), Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
    sheets = workbook.Worksheets;
    foreach (Worksheet ws in sheets)
    {
        if (ws.Index == 5)
            NwSheet = ws;
        if (ws.Index == 1)
            NwSheetSummary = ws;
        if (ws.Index == 4)
            NwSheetIndividualTotal = ws;
    }

    //Reading Excel file.
    //Creating datatable to read the containt of the Sheet in File.
    System.Data.DataTable dt = export.Tables[0];

    int rowCount = 8;

    if (dt.Columns.Contains("RowID"))
        dt.Columns.Remove("RowID");
    if (dt.Columns.Contains("Week"))
        dt.Columns.Remove("Week");
    if (dt.Columns.Contains("Year"))
        dt.Columns.Remove("Year");
    foreach (DataRow dr in dt.Rows)
    {

        rowCount += 1;
        for (int i = 1; i < dt.Columns.Count + 1; i++)
        {
            // Add the header the first time through 
            if (rowCount == 8)
            {
                //NwSheet.Cells[1, i] = dt.Columns[i - 1].ColumnName;
            }
            NwSheet.Cells[rowCount, i] = dr[i - 1].ToString();
        }
    }

    for (int count = 0; count <= dt.Rows.Count; count++)
    {
        // NwSheet.get_Range("A9", Missing.Value).Value2 = dt.Rows[count]["SlNo"].ToString();


    }开发者_StackOverflow中文版
    workbook.RefreshAll();
    String path = Convert.ToString(ConfigurationManager.AppSettings["DefaultPath"]);

    CreateFileOrFolder(workbook, week);
    NwSheet = null;
    ShtRange = null;
    workbook.Close(Missing.Value, Missing.Value, Missing.Value);
    workbook = null;
    oXL.Quit();
    excel.Quit();
    //appExl.Quit();
    status = true;
}

Now it run's fine in my local PC which has Interop Excel 12.0 but not when hosted in server machine which has same 12.0.

the error received is

Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80070005.

After googling out for the error I had gone through other forums and they had mentioned to give rights to Network Services to Microsoft Excel Application in dcomcnfg. I did the same thing but its of no use.

It didnt worked out and I got the same error. Like :- Configuration of dcomcnfge

Which Say's:-

Goto Control-Panel --> Administrative tools-->Component Services -->computers --> myComputer -->DCOM Config --> Microsoft Excel Application. --> Right click to get properties dialog. Goto Security tab and customize permissions accordingly.

I have tried giving all possible right's but still the error persist's.!!

Please help..

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜