none
C#创建Excel对象爆出异常 RRS feed

  • 问题

  • 我的系统部署在server 2008

    我的方法如下:

     void initailExcel()
            {
                bool flag = false;
                foreach (var item in Process.GetProcesses())
                {
                    if (item.ProcessName == "EXCEL")
                    {
                        flag = true;
                        break;
                    }
                }
                if (!flag)
                {
                    this._Excel = new Microsoft.Office.Interop.Excel.Application();
                    this._Excel.Visible = false;//false is better
                    this._Excel.DisplayAlerts = false; //屏蔽关闭Excel没有保存弹出的“是否保存”的对话框 add by qqshi
                }
                else
                {
                    object obj = Marshal.GetActiveObject("Excel.Application");
                    _Excel = obj as Microsoft.Office.Interop.Excel.Application;
                }

    }

    异常log:

    2018/3/16 9:52:43 Debug :System.Runtime.InteropServices.COMException (0x8000401A): Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 8000401a The server process could not be started because the configured identity is incorrect. Check the username and password. (Exception from HRESULT: 0x8000401A).
       at System.Runtime.Remoting.RemotingServices.AllocateUninitializedObject(RuntimeType objectType)
       at System.Runtime.Remoting.Activation.ActivationServices.CreateInstance(RuntimeType serverType)
       at System.Runtime.Remoting.Activation.ActivationServices.IsCurrentContextOK(RuntimeType serverType, Object[] props, Boolean bNewObj)
       at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
       at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache)
       at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean skipCheckThis, Boolean fillCache)
       at System.Activator.CreateInstance(Type type, Boolean nonPublic)
       at System.Activator.CreateInstance(Type type)
       at PQMWeb.ApplyForm.PQC.initailExcel() in D:\SourceCode\PartsQualityManage_20171010\PQMWeb\ApplyForm\PQC.aspx.cs:line 663
       at PQMWeb.ApplyForm.PQC.btnSendMail_Click(Object sender, EventArgs e) in D:\SourceCode\PartsQualityManage_20171010\PQMWeb\ApplyForm\PQC.aspx.cs:line 563

    请问如何解决,谢谢

    2018年3月16日 5:14

全部回复